@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/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.6",
333
+ version: "2.3.7",
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",
@@ -2579,13 +2579,16 @@ __export(server_exports, {
2579
2579
  EmbeddingFailedException: () => EmbeddingFailedException,
2580
2580
  EmbeddingStrategy: () => EmbeddingStrategy,
2581
2581
  EmbeddingStrategyResolver: () => EmbeddingStrategyResolver,
2582
+ EventType: () => EventType,
2582
2583
  GroqProvider: () => GroqProvider,
2583
2584
  IntentClassifier: () => IntentClassifier,
2584
2585
  LLMFactory: () => LLMFactory,
2585
2586
  LLM_PROFILES: () => LLM_PROFILES,
2587
+ LicenseConfigResolver: () => LicenseConfigResolver,
2586
2588
  LicenseValidationError: () => LicenseValidationError,
2587
2589
  LicenseValidator: () => LicenseValidator,
2588
2590
  LicenseVerifier: () => LicenseVerifier,
2591
+ LicensedRetrivora: () => LicensedRetrivora,
2589
2592
  MilvusProvider: () => MilvusProvider,
2590
2593
  MixedRendererStrategy: () => MixedRendererStrategy,
2591
2594
  MongoDBProvider: () => MongoDBProvider,
@@ -2618,6 +2621,7 @@ __export(server_exports, {
2618
2621
  SDKVersionUnsupportedError: () => SDKVersionUnsupportedError,
2619
2622
  SDK_VERSION: () => SDK_VERSION,
2620
2623
  TableRendererStrategy: () => TableRendererStrategy,
2624
+ TelemetryService: () => TelemetryService,
2621
2625
  TextRendererStrategy: () => TextRendererStrategy,
2622
2626
  UniversalLLMAdapter: () => UniversalLLMAdapter,
2623
2627
  UniversalVectorProvider: () => UniversalVectorProvider,
@@ -2633,13 +2637,19 @@ __export(server_exports, {
2633
2637
  createHistoryHandler: () => createHistoryHandler,
2634
2638
  createIngestHandler: () => createIngestHandler,
2635
2639
  createRagHandler: () => createRagHandler,
2640
+ createRetrivora: () => createRetrivora,
2636
2641
  createSessionsHandler: () => createSessionsHandler,
2637
2642
  createStreamHandler: () => createStreamHandler,
2638
2643
  createUploadHandler: () => createUploadHandler,
2639
2644
  decideVisualization: () => decideVisualization,
2640
2645
  getRagConfig: () => getRagConfig,
2646
+ getRuntimeConfig: () => getRuntimeConfig,
2647
+ getTelemetryService: () => getTelemetryService,
2648
+ initializeTelemetryService: () => initializeTelemetryService,
2649
+ injectRuntimeConfig: () => injectRuntimeConfig,
2641
2650
  normalizeProjectSettings: () => normalizeProjectSettings,
2642
2651
  projectSettingsToUiConfig: () => projectSettingsToUiConfig,
2652
+ shutdownTelemetryService: () => shutdownTelemetryService,
2643
2653
  sseErrorFrame: () => sseErrorFrame,
2644
2654
  sseFrame: () => sseFrame,
2645
2655
  sseMetaFrame: () => sseMetaFrame,
@@ -2937,13 +2947,13 @@ LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
2937
2947
  // In production, this matches the private key held by Retrivora SaaS.
2938
2948
  // Rotate this key only when the signing private key is replaced.
2939
2949
  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
2950
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
2951
+ jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
2952
+ Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
2953
+ 6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
2954
+ sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
2955
+ 6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
2956
+ 6QIDAQAB
2947
2957
  -----END PUBLIC KEY-----`;
2948
2958
 
2949
2959
  // src/config/constants.ts
@@ -2992,6 +3002,20 @@ var PROVIDERS_WITH_EMBEDDINGS = [
2992
3002
  var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
2993
3003
 
2994
3004
  // src/config/serverConfig.ts
3005
+ var _runtimeConfig = null;
3006
+ function injectRuntimeConfig(config) {
3007
+ _runtimeConfig = config;
3008
+ console.log("[serverConfig] \u2705 Runtime tier config injected:", {
3009
+ tier: config.tier,
3010
+ llmModel: config.llmModel,
3011
+ embeddingModel: config.embeddingModel,
3012
+ llmBaseUrl: config.llmBaseUrl,
3013
+ hasLitellmKey: !!config.litellmApiKey
3014
+ });
3015
+ }
3016
+ function getRuntimeConfig() {
3017
+ return _runtimeConfig;
3018
+ }
2995
3019
  function readString(env, name) {
2996
3020
  var _a3;
2997
3021
  const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
@@ -3018,7 +3042,7 @@ function getRagConfig(baseConfig, env = process.env) {
3018
3042
  return getEnvConfig(env, baseConfig);
3019
3043
  }
3020
3044
  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, _Ib, _Jb, _Kb;
3045
+ var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb;
3022
3046
  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
3047
  const jwtProjectId = (() => {
3024
3048
  if (!licenseKey) return void 0;
@@ -3110,25 +3134,35 @@ function getEnvConfig(env = process.env, base) {
3110
3134
  return true;
3111
3135
  }
3112
3136
  })();
3113
- const defaultGatewayUrl = (_ra = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _ra : "https://www.retrivora.com/api/v1";
3114
- const defaultLlmProvider = isFreeTier2 ? "universal_rest" : "universal_rest";
3115
- const llmProvider = (_ua = (_ta = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ta : (_sa = base == null ? void 0 : base.llm) == null ? void 0 : _sa.provider) != null ? _ua : defaultLlmProvider;
3116
- const llmBaseUrl = (_ya = (_xa = (_va = readString(env, "LITELLM_BASE_URL")) != null ? _va : readString(env, "LLM_BASE_URL")) != null ? _xa : (_wa = base == null ? void 0 : base.llm) == null ? void 0 : _wa.baseUrl) != null ? _ya : defaultGatewayUrl;
3117
- const llmModel = (_Ca = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ca : isFreeTier2 ? "llama-3.1-8b-instant" : (_Ba = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _Ba : "gpt-4o";
3118
- const llmApiKey = (_Ia = (_Ha = (_Fa = (_Ea = (_Da = llmApiKeyByProvider[llmProvider]) != null ? _Da : readString(env, "LLM_API_KEY")) != null ? _Ea : readString(env, "LITELLM_MASTER_KEY")) != null ? _Fa : readString(env, "LITELLM_API_KEY")) != null ? _Ha : (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.apiKey) != null ? _Ia : licenseKey;
3119
- const llmProfile = (_Ma = (_La = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _La : (_Ka = (_Ja = base == null ? void 0 : base.llm) == null ? void 0 : _Ja.options) == null ? void 0 : _Ka.profile) != null ? _Ma : "litellm";
3120
- const defaultEmbeddingProvider = isFreeTier2 ? "universal_rest" : "universal_rest";
3121
- const embeddingProvider = (_Pa = (_Oa = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Oa : (_Na = base == null ? void 0 : base.embedding) == null ? void 0 : _Na.provider) != null ? _Pa : defaultEmbeddingProvider;
3122
- const embeddingBaseUrl = (_Ua = (_Ta = (_Ra = (_Qa = readString(env, "LITELLM_BASE_URL")) != null ? _Qa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Ra : readString(env, "LLM_BASE_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.embedding) == null ? void 0 : _Sa.baseUrl) != null ? _Ua : defaultGatewayUrl;
3123
- const embeddingModel = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : "text-embedding-004";
3124
- const embeddingApiKey = (_cb = (_bb = (_$a = (__a = (_Za = (_Ya = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ya : readString(env, "EMBEDDING_API_KEY")) != null ? _Za : readString(env, "LLM_API_KEY")) != null ? __a : readString(env, "LITELLM_MASTER_KEY")) != null ? _$a : readString(env, "LITELLM_API_KEY")) != null ? _bb : (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.apiKey) != null ? _cb : licenseKey;
3125
- const embeddingProfile = (_gb = (_fb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _fb : (_eb = (_db = base == null ? void 0 : base.embedding) == null ? void 0 : _db.options) == null ? void 0 : _eb.profile) != null ? _gb : "litellm";
3137
+ const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
3138
+ const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
3139
+ const defaultGatewayUrl = "https://llm.retrivora.com/api/v1";
3140
+ const rt = _runtimeConfig;
3141
+ const defaultLlmProvider = "universal_rest";
3142
+ 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;
3143
+ 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;
3144
+ 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;
3145
+ 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;
3146
+ 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";
3147
+ console.log("[serverConfig] \u{1F527} LLM Configuration:", {
3148
+ baseUrl: llmBaseUrl,
3149
+ model: llmModel,
3150
+ provider: llmProvider,
3151
+ hasApiKey: !!llmApiKey,
3152
+ source: (rt == null ? void 0 : rt.llmModel) ? "runtime-injected" : "env/fallback"
3153
+ });
3154
+ const defaultEmbeddingProvider = "universal_rest";
3155
+ 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;
3156
+ 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;
3157
+ 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;
3158
+ 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;
3159
+ 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
3160
  return __spreadProps(__spreadValues({
3127
3161
  projectId,
3128
3162
  licenseKey,
3129
3163
  vectorDb: {
3130
3164
  provider: vectorProvider,
3131
- indexName: (_ib = (_hb = readString(env, "VECTOR_DB_INDEX")) != null ? _hb : vectorDbOptions.indexName) != null ? _ib : "rag-index",
3165
+ indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
3132
3166
  options: vectorDbOptions
3133
3167
  },
3134
3168
  llm: {
@@ -3158,30 +3192,30 @@ function getEnvConfig(env = process.env, base) {
3158
3192
  }
3159
3193
  },
3160
3194
  ui: {
3161
- title: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _jb : readString(env, "UI_TITLE")) != null ? _kb : "AI Assistant",
3162
- subtitle: (_mb = (_lb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _lb : readString(env, "UI_SUBTITLE")) != null ? _mb : "Powered by RAG",
3163
- primaryColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _nb : readString(env, "UI_PRIMARY_COLOR")) != null ? _ob : "#10b981",
3164
- accentColor: (_qb = (_pb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _pb : readString(env, "UI_ACCENT_COLOR")) != null ? _qb : "#3b82f6",
3165
- logoUrl: (_rb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _rb : readString(env, "UI_LOGO_URL"),
3166
- placeholder: (_tb = (_sb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _sb : readString(env, "UI_PLACEHOLDER")) != null ? _tb : "Ask me anything\u2026",
3167
- showSources: ((_vb = (_ub = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _ub : readString(env, "UI_SHOW_SOURCES")) != null ? _vb : "true") !== "false",
3168
- welcomeMessage: (_xb = (_wb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _wb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _xb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
3169
- visualStyle: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _yb : readString(env, "UI_VISUAL_STYLE")) != null ? _zb : "glass",
3170
- borderRadius: (_Bb = (_Ab = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ab : readString(env, "UI_BORDER_RADIUS")) != null ? _Bb : "xl",
3171
- allowUpload: ((_Db = (_Cb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Cb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Db : "false") === "true"
3195
+ title: (_hb = (_gb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _gb : readString(env, "UI_TITLE")) != null ? _hb : "AI Assistant",
3196
+ subtitle: (_jb = (_ib = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _ib : readString(env, "UI_SUBTITLE")) != null ? _jb : "Powered by RAG",
3197
+ primaryColor: (_lb = (_kb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _kb : readString(env, "UI_PRIMARY_COLOR")) != null ? _lb : "#10b981",
3198
+ accentColor: (_nb = (_mb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _mb : readString(env, "UI_ACCENT_COLOR")) != null ? _nb : "#3b82f6",
3199
+ logoUrl: (_ob = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _ob : readString(env, "UI_LOGO_URL"),
3200
+ placeholder: (_qb = (_pb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _pb : readString(env, "UI_PLACEHOLDER")) != null ? _qb : "Ask me anything\u2026",
3201
+ showSources: ((_sb = (_rb = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _rb : readString(env, "UI_SHOW_SOURCES")) != null ? _sb : "true") !== "false",
3202
+ 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.",
3203
+ visualStyle: (_wb = (_vb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _vb : readString(env, "UI_VISUAL_STYLE")) != null ? _wb : "glass",
3204
+ borderRadius: (_yb = (_xb = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _xb : readString(env, "UI_BORDER_RADIUS")) != null ? _yb : "xl",
3205
+ allowUpload: ((_Ab = (_zb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _zb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Ab : "false") === "true"
3172
3206
  },
3173
3207
  rag: {
3174
3208
  topK: readNumber(env, "RAG_TOP_K", 5),
3175
3209
  scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
3176
3210
  chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
3177
3211
  chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
3178
- filterableFields: (_Eb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Eb.split(",").map((f) => f.trim()),
3212
+ filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
3179
3213
  // Query pipeline toggles — read from .env.local
3180
3214
  useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
3181
3215
  useReranking: readString(env, "RAG_USE_RERANKING") === "true",
3182
3216
  useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
3183
- architecture: (_Fb = readString(env, "RAG_ARCHITECTURE")) != null ? _Fb : "simple",
3184
- chunkingStrategy: (_Gb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Gb : "recursive",
3217
+ architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
3218
+ chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
3185
3219
  uiMapping: (() => {
3186
3220
  const raw = readString(env, "RAG_UI_MAPPING");
3187
3221
  if (!raw) return void 0;
@@ -3194,7 +3228,7 @@ function getEnvConfig(env = process.env, base) {
3194
3228
  },
3195
3229
  telemetry: {
3196
3230
  enabled: telemetryEnabled,
3197
- url: (_Kb = (_Jb = (_Hb = readString(env, "TELEMETRY_URL")) != null ? _Hb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Jb : (_Ib = base == null ? void 0 : base.telemetry) == null ? void 0 : _Ib.url) != null ? _Kb : "https://www.retrivora.com/api/telemetry"
3231
+ 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
3232
  }
3199
3233
  }, readString(env, "GRAPH_DB_PROVIDER") ? {
3200
3234
  graphDb: {
@@ -3718,8 +3752,8 @@ var OllamaProvider = class {
3718
3752
  const baseUrl = config.baseUrl || "http://localhost:11434";
3719
3753
  const modelName = config.model;
3720
3754
  try {
3721
- const axios9 = (await import("axios")).default;
3722
- const { data } = await axios9.get(`${baseUrl}/api/tags`);
3755
+ const axios11 = (await import("axios")).default;
3756
+ const { data } = await axios11.get(`${baseUrl}/api/tags`);
3723
3757
  const models = data.models || [];
3724
3758
  const hasModel = models.some((m) => m.name === modelName || m.name.startsWith(`${modelName}:`));
3725
3759
  return {
@@ -4551,7 +4585,7 @@ var UniversalLLMAdapter = class {
4551
4585
  });
4552
4586
  }
4553
4587
  async chat(messages, context) {
4554
- var _a3, _b, _c, _d, _e;
4588
+ var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
4555
4589
  const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
4556
4590
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4557
4591
  role: m.role || "user",
@@ -4581,16 +4615,27 @@ ${context != null ? context : "None"}` },
4581
4615
  };
4582
4616
  }
4583
4617
  try {
4618
+ console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
4619
+ console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
4620
+ console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
4584
4621
  const { data: data2 } = await this.http.post(path2, payload);
4585
- const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4586
- const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4622
+ const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
4623
+ const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
4587
4624
  if (result2 !== void 0) {
4588
4625
  return String(result2);
4589
4626
  }
4590
4627
  } catch (httpErr) {
4591
- const _g2 = globalThis;
4592
- const dispatch = _g2.__retrivoraDispatchChat;
4628
+ console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
4629
+ status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
4630
+ statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
4631
+ url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
4632
+ errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
4633
+ message: httpErr == null ? void 0 : httpErr.message
4634
+ });
4635
+ const _g3 = globalThis;
4636
+ const dispatch = _g3.__retrivoraDispatchChat;
4593
4637
  if (typeof dispatch === "function") {
4638
+ console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
4594
4639
  const res = await dispatch({
4595
4640
  model: this.model,
4596
4641
  messages: formattedMessages,
@@ -4605,8 +4650,8 @@ ${context != null ? context : "None"}` },
4605
4650
  throw httpErr;
4606
4651
  }
4607
4652
  const { data } = await this.http.post(path2, payload);
4608
- const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4609
- const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4653
+ const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
4654
+ const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
4610
4655
  if (result === void 0) {
4611
4656
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4612
4657
  }
@@ -4745,36 +4790,70 @@ ${context != null ? context : "None"}` },
4745
4790
  });
4746
4791
  }
4747
4792
  async embed(text) {
4748
- var _a3, _b, _c, _d, _e;
4793
+ var _a3, _b, _c, _d, _e, _f, _g2;
4749
4794
  const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
4750
4795
  const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
4751
4796
  try {
4752
- const { data: data2 } = await this.http.post(path2, payload);
4753
- const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4754
- const vector2 = resolvePath(data2, extractPath2);
4755
- if (Array.isArray(vector2)) return vector2;
4756
- } catch (e) {
4757
- const _g2 = globalThis;
4758
- const dispatchEmbed = _g2.__retrivoraDispatchEmbedding;
4797
+ const { data } = await this.http.post(path2, payload);
4798
+ const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4799
+ const vector = resolvePath(data, extractPath);
4800
+ if (Array.isArray(vector)) return vector;
4801
+ console.warn(
4802
+ `[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
4803
+ data
4804
+ );
4805
+ } catch (err) {
4806
+ console.warn(
4807
+ `[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
4808
+ { path: path2, model: this.model }
4809
+ );
4810
+ const _g3 = globalThis;
4811
+ const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
4759
4812
  if (typeof dispatchEmbed === "function") {
4760
- const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4761
- if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4762
- return res.data[0].embedding;
4813
+ try {
4814
+ const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
4815
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4816
+ return res.data[0].embedding;
4817
+ }
4818
+ } catch (dispatchErr) {
4819
+ console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
4763
4820
  }
4764
4821
  }
4765
4822
  }
4766
- const { data } = await this.http.post(path2, payload);
4767
- const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4768
- const vector = resolvePath(data, extractPath);
4769
- if (!Array.isArray(vector)) {
4770
- throw new Error(`[UniversalLLMAdapter] Could not extract embedding vector from path '${extractPath}' in response.`);
4823
+ try {
4824
+ const { data } = await this.http.post(path2, payload);
4825
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4826
+ const vector = resolvePath(data, extractPath);
4827
+ if (Array.isArray(vector)) {
4828
+ return vector;
4829
+ }
4830
+ console.error(
4831
+ `[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
4832
+ data
4833
+ );
4834
+ throw new Error(
4835
+ `[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
4836
+ );
4837
+ } catch (err) {
4838
+ console.error(
4839
+ `[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
4840
+ { 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 }
4841
+ );
4842
+ throw new Error(
4843
+ `[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
4844
+ );
4771
4845
  }
4772
- return vector;
4773
4846
  }
4774
4847
  async batchEmbed(texts) {
4775
4848
  const results = [];
4776
4849
  for (const text of texts) {
4777
- results.push(await this.embed(text));
4850
+ try {
4851
+ const vector = await this.embed(text);
4852
+ results.push(vector);
4853
+ } catch (err) {
4854
+ console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
4855
+ throw err;
4856
+ }
4778
4857
  }
4779
4858
  return results;
4780
4859
  }
@@ -11825,6 +11904,7 @@ function createUploadHandler(configOrPlugin, options) {
11825
11904
  const plugin = getOrCreatePlugin(configOrPlugin);
11826
11905
  const onAuthorize = options == null ? void 0 : options.onAuthorize;
11827
11906
  return async function POST(req, context) {
11907
+ console.log("Upload handler invoked");
11828
11908
  const authResult = await checkAuth(req, onAuthorize);
11829
11909
  if (authResult) return authResult;
11830
11910
  const config = plugin.getConfig();
@@ -11833,6 +11913,7 @@ function createUploadHandler(configOrPlugin, options) {
11833
11913
  try {
11834
11914
  const formData = await req.formData();
11835
11915
  const files = formData.getAll("files");
11916
+ console.log("Files received for upload:", files.map((f) => f.name));
11836
11917
  const namespace = formData.get("namespace") || void 0;
11837
11918
  const dimensionRaw = formData.get("dimension");
11838
11919
  const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
@@ -12386,6 +12467,583 @@ var _LicenseValidator = class _LicenseValidator {
12386
12467
  };
12387
12468
  _LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
12388
12469
  var LicenseValidator = _LicenseValidator;
12470
+
12471
+ // src/config/LicenseConfigResolver.ts
12472
+ var import_axios9 = __toESM(require("axios"));
12473
+ var LicenseConfigResolver = class {
12474
+ /**
12475
+ * Validate and resolve configuration from license key
12476
+ * @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
12477
+ * @param projectId Workspace identifier
12478
+ * @returns Resolved LLM and embedding configs with provider credentials
12479
+ */
12480
+ static async resolveFromLicense(licenseKey, projectId) {
12481
+ const cacheKey = `${licenseKey}:${projectId}`;
12482
+ const cached = this.configCache.get(cacheKey);
12483
+ if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
12484
+ console.log("[LicenseConfigResolver] Using cached config for", projectId);
12485
+ return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
12486
+ }
12487
+ console.log("[LicenseConfigResolver] Fetching tier config from Retrivora...");
12488
+ const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
12489
+ console.log("[LicenseConfigResolver] Fetching provider credentials from Retrivora...");
12490
+ const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
12491
+ this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
12492
+ console.log("[LicenseConfigResolver] \u2705 Successfully resolved config from Retrivora:", {
12493
+ tier: tierConfig.tier,
12494
+ llmModel: tierConfig.llmModel,
12495
+ embeddingModel: tierConfig.embeddingModel
12496
+ });
12497
+ return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
12498
+ }
12499
+ /**
12500
+ * Fetch tier configuration from Retrivora config API
12501
+ */
12502
+ static async fetchTierConfig(licenseKey, projectId) {
12503
+ try {
12504
+ const response = await import_axios9.default.post(
12505
+ this.RETRIVORA_CONFIG_URL,
12506
+ { licenseKey, projectId },
12507
+ {
12508
+ headers: {
12509
+ "Content-Type": "application/json",
12510
+ Authorization: `Bearer ${licenseKey}`,
12511
+ "X-License-Key": licenseKey,
12512
+ "X-Project-ID": projectId
12513
+ },
12514
+ timeout: 1e4
12515
+ }
12516
+ );
12517
+ if (!response.data.success || !response.data.config) {
12518
+ throw new Error(
12519
+ `[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
12520
+ );
12521
+ }
12522
+ console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
12523
+ return response.data.config;
12524
+ } catch (err) {
12525
+ console.error("[LicenseConfigResolver] Failed to fetch config:", err.message);
12526
+ throw new Error(
12527
+ `[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
12528
+ );
12529
+ }
12530
+ }
12531
+ /**
12532
+ * Fetch provider credentials from Retrivora credentials API
12533
+ */
12534
+ static async fetchProviderCredentials(licenseKey, projectId) {
12535
+ try {
12536
+ const response = await import_axios9.default.post(
12537
+ this.RETRIVORA_CREDENTIALS_URL,
12538
+ { licenseKey, projectId },
12539
+ {
12540
+ headers: {
12541
+ "Content-Type": "application/json",
12542
+ Authorization: `Bearer ${licenseKey}`,
12543
+ "X-License-Key": licenseKey,
12544
+ "X-Project-ID": projectId
12545
+ },
12546
+ timeout: 1e4
12547
+ }
12548
+ );
12549
+ if (!response.data.success || !response.data.credentials) {
12550
+ throw new Error(
12551
+ `[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
12552
+ );
12553
+ }
12554
+ console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
12555
+ return response.data.credentials;
12556
+ } catch (err) {
12557
+ console.error("[LicenseConfigResolver] Failed to fetch credentials:", err.message);
12558
+ throw new Error(
12559
+ `[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
12560
+ );
12561
+ }
12562
+ }
12563
+ /**
12564
+ * Build LLM, embedding, and vector DB configs from tier and credentials
12565
+ */
12566
+ static buildConfigs(tierConfig, credentials, licenseKey, projectId) {
12567
+ let llmProvider = "gemini";
12568
+ let llmApiKey = credentials.geminiApiKey || licenseKey;
12569
+ if (tierConfig.llmModel.includes("gpt")) {
12570
+ llmProvider = "openai";
12571
+ } else if (tierConfig.llmModel.includes("groq") || tierConfig.llmModel.includes("llama")) {
12572
+ llmProvider = "groq";
12573
+ llmApiKey = credentials.groqApiKey || licenseKey;
12574
+ }
12575
+ const llmConfig = {
12576
+ provider: llmProvider,
12577
+ model: tierConfig.llmModel,
12578
+ apiKey: llmApiKey,
12579
+ maxTokens: tierConfig.maxTokens,
12580
+ temperature: 0.7,
12581
+ options: {}
12582
+ };
12583
+ const embeddingConfig = {
12584
+ provider: "gemini",
12585
+ model: tierConfig.embeddingModel,
12586
+ apiKey: credentials.geminiApiKey || licenseKey,
12587
+ dimensions: tierConfig.embeddingDimensions,
12588
+ options: {}
12589
+ };
12590
+ const vectorDbConfig = {
12591
+ provider: tierConfig.vectorDb.provider,
12592
+ indexName: tierConfig.vectorDb.indexName,
12593
+ options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials)
12594
+ };
12595
+ return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
12596
+ }
12597
+ /**
12598
+ * Get provider-specific vector DB options
12599
+ */
12600
+ static getVectorDbOptions(provider, projectId, credentials) {
12601
+ switch (provider) {
12602
+ case "pinecone":
12603
+ return {
12604
+ apiKey: credentials.pineconeApiKey,
12605
+ indexName: `retrivora-${projectId}`
12606
+ };
12607
+ case "pgvector":
12608
+ case "postgresql":
12609
+ return {
12610
+ tables: [`documents_${projectId}`]
12611
+ };
12612
+ case "mongodb":
12613
+ return {
12614
+ database: `retrivora_${projectId}`,
12615
+ collection: `vectors_${projectId}`
12616
+ };
12617
+ case "qdrant":
12618
+ return {
12619
+ collection: `retrivora_${projectId}`
12620
+ };
12621
+ default:
12622
+ return {};
12623
+ }
12624
+ }
12625
+ /**
12626
+ * Clear configuration cache (useful for testing or manual refresh)
12627
+ */
12628
+ static clearCache() {
12629
+ this.configCache.clear();
12630
+ console.log("[LicenseConfigResolver] Configuration cache cleared");
12631
+ }
12632
+ /**
12633
+ * Get cache stats for debugging
12634
+ */
12635
+ static getCacheStats() {
12636
+ return {
12637
+ size: this.configCache.size,
12638
+ entries: Array.from(this.configCache.keys())
12639
+ };
12640
+ }
12641
+ };
12642
+ LicenseConfigResolver.RETRIVORA_CONFIG_URL = "https://www.retrivora.com/api/v1/config";
12643
+ LicenseConfigResolver.RETRIVORA_CREDENTIALS_URL = "https://www.retrivora.com/api/v1/credentials";
12644
+ LicenseConfigResolver.CACHE_TTL_MS = 36e5;
12645
+ // 1 hour
12646
+ LicenseConfigResolver.configCache = /* @__PURE__ */ new Map();
12647
+
12648
+ // src/telemetry/TelemetryService.ts
12649
+ var import_axios10 = __toESM(require("axios"));
12650
+ var EventType = /* @__PURE__ */ ((EventType2) => {
12651
+ EventType2["EMBEDDING_GENERATED"] = "embedding_generated";
12652
+ EventType2["LLM_CHAT_COMPLETION"] = "llm_chat_completion";
12653
+ EventType2["DOCUMENT_INGESTED"] = "document_ingested";
12654
+ EventType2["QUERY_EXECUTED"] = "query_executed";
12655
+ EventType2["ERROR_OCCURRED"] = "error_occurred";
12656
+ EventType2["CONFIGURATION_LOADED"] = "configuration_loaded";
12657
+ return EventType2;
12658
+ })(EventType || {});
12659
+ var _TelemetryService = class _TelemetryService {
12660
+ constructor(projectId, licenseKey, userTelemetryUrl) {
12661
+ this.batchSize = 10;
12662
+ this.flushIntervalMs = 3e4;
12663
+ // 30 seconds
12664
+ this.eventQueue = [];
12665
+ this.enabled = true;
12666
+ this.projectId = projectId;
12667
+ this.licenseKey = licenseKey;
12668
+ this.userTelemetryUrl = userTelemetryUrl || process.env[_TelemetryService.USER_TELEMETRY_URL_ENV_KEY];
12669
+ this.http = import_axios10.default.create({
12670
+ timeout: 5e3,
12671
+ headers: {
12672
+ "Content-Type": "application/json",
12673
+ "X-License-Key": licenseKey,
12674
+ "X-Project-ID": projectId
12675
+ }
12676
+ });
12677
+ this.startAutoFlush();
12678
+ }
12679
+ /**
12680
+ * Record a telemetry event
12681
+ */
12682
+ recordEvent(event) {
12683
+ if (!this.enabled) return;
12684
+ const _a3 = event, { licenseKey } = _a3, safeEvent = __objRest(_a3, ["licenseKey"]);
12685
+ const completeEvent = __spreadValues({
12686
+ eventType: event.eventType || "error_occurred" /* ERROR_OCCURRED */,
12687
+ projectId: this.projectId,
12688
+ timestamp: event.timestamp || Date.now()
12689
+ }, safeEvent);
12690
+ this.eventQueue.push(completeEvent);
12691
+ if (this.eventQueue.length >= this.batchSize) {
12692
+ this.flush().catch((err) => {
12693
+ console.warn("[TelemetryService] Flush error:", err.message);
12694
+ });
12695
+ }
12696
+ }
12697
+ /**
12698
+ * Record LLM completion event
12699
+ */
12700
+ recordLLMCompletion(data) {
12701
+ this.recordEvent({
12702
+ eventType: "llm_chat_completion" /* LLM_CHAT_COMPLETION */,
12703
+ model: data.model,
12704
+ inputTokens: data.inputTokens,
12705
+ outputTokens: data.outputTokens,
12706
+ totalTokens: data.inputTokens + data.outputTokens,
12707
+ durationMs: data.durationMs,
12708
+ operationId: data.operationId,
12709
+ metadata: data.metadata
12710
+ });
12711
+ }
12712
+ /**
12713
+ * Record embedding generation event
12714
+ */
12715
+ recordEmbeddingGenerated(data) {
12716
+ this.recordEvent({
12717
+ eventType: "embedding_generated" /* EMBEDDING_GENERATED */,
12718
+ embeddingModel: data.embeddingModel,
12719
+ vectorDimensions: data.vectorDimensions,
12720
+ textLength: data.textLength,
12721
+ durationMs: data.durationMs,
12722
+ operationId: data.operationId
12723
+ });
12724
+ }
12725
+ /**
12726
+ * Record document ingestion event
12727
+ */
12728
+ recordDocumentIngested(data) {
12729
+ this.recordEvent({
12730
+ eventType: "document_ingested" /* DOCUMENT_INGESTED */,
12731
+ documentId: data.documentId,
12732
+ documentName: data.documentName,
12733
+ documentSize: data.documentSize,
12734
+ chunksGenerated: data.chunksGenerated,
12735
+ durationMs: data.durationMs
12736
+ });
12737
+ }
12738
+ /**
12739
+ * Record query execution event
12740
+ */
12741
+ recordQueryExecuted(data) {
12742
+ this.recordEvent({
12743
+ eventType: "query_executed" /* QUERY_EXECUTED */,
12744
+ queryText: data.queryText,
12745
+ resultCount: data.resultCount,
12746
+ durationMs: data.durationMs,
12747
+ operationId: data.operationId
12748
+ });
12749
+ }
12750
+ /**
12751
+ * Record error event
12752
+ */
12753
+ recordError(error, context) {
12754
+ this.recordEvent({
12755
+ eventType: "error_occurred" /* ERROR_OCCURRED */,
12756
+ errorCode: error.code || "UNKNOWN",
12757
+ errorMessage: error.message,
12758
+ stackTrace: error.stack,
12759
+ metadata: context
12760
+ });
12761
+ }
12762
+ /**
12763
+ * Flush all queued events to telemetry endpoints
12764
+ */
12765
+ async flush() {
12766
+ if (this.eventQueue.length === 0) return;
12767
+ const events = this.eventQueue.splice(0, this.batchSize);
12768
+ const payload = {
12769
+ events: events.map((e) => {
12770
+ const eventWithoutKey = __objRest(e, []);
12771
+ return eventWithoutKey;
12772
+ }),
12773
+ batchId: `${this.projectId}_${Date.now()}`
12774
+ };
12775
+ try {
12776
+ await this.http.post(_TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
12777
+ console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
12778
+ } catch (err) {
12779
+ console.warn("[TelemetryService] Failed to send telemetry to Retrivora:", err.message);
12780
+ this.eventQueue.unshift(...events);
12781
+ }
12782
+ if (this.userTelemetryUrl) {
12783
+ try {
12784
+ await import_axios10.default.post(this.userTelemetryUrl, payload, {
12785
+ timeout: 5e3,
12786
+ headers: {
12787
+ "Content-Type": "application/json",
12788
+ "X-Project-ID": this.projectId
12789
+ }
12790
+ });
12791
+ console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
12792
+ } catch (err) {
12793
+ console.warn("[TelemetryService] Failed to send telemetry to user endpoint:", err.message);
12794
+ }
12795
+ }
12796
+ }
12797
+ /**
12798
+ * Start automatic flush interval
12799
+ */
12800
+ startAutoFlush() {
12801
+ this.flushTimer = setInterval(() => {
12802
+ this.flush().catch((err) => {
12803
+ console.warn("[TelemetryService] Auto-flush error:", err.message);
12804
+ });
12805
+ }, this.flushIntervalMs);
12806
+ }
12807
+ /**
12808
+ * Stop telemetry service and flush remaining events
12809
+ */
12810
+ async shutdown() {
12811
+ if (this.flushTimer) {
12812
+ clearInterval(this.flushTimer);
12813
+ }
12814
+ await this.flush();
12815
+ this.enabled = false;
12816
+ }
12817
+ /**
12818
+ * Disable telemetry temporarily
12819
+ */
12820
+ disable() {
12821
+ this.enabled = false;
12822
+ }
12823
+ /**
12824
+ * Enable telemetry
12825
+ */
12826
+ enable() {
12827
+ this.enabled = true;
12828
+ }
12829
+ /**
12830
+ * Get current queue size (for debugging)
12831
+ */
12832
+ getQueueSize() {
12833
+ return this.eventQueue.length;
12834
+ }
12835
+ };
12836
+ _TelemetryService.RETRIVORA_TELEMETRY_URL = "https://www.retrivora.com/api/telemetry";
12837
+ _TelemetryService.USER_TELEMETRY_URL_ENV_KEY = "TELEMETRY_URL";
12838
+ var TelemetryService = _TelemetryService;
12839
+ var globalTelemetryService = null;
12840
+ function getTelemetryService() {
12841
+ return globalTelemetryService;
12842
+ }
12843
+ function initializeTelemetryService(projectId, licenseKey, userTelemetryUrl) {
12844
+ globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
12845
+ console.log("[TelemetryService] Initialized for project:", projectId);
12846
+ return globalTelemetryService;
12847
+ }
12848
+ async function shutdownTelemetryService() {
12849
+ if (globalTelemetryService) {
12850
+ await globalTelemetryService.shutdown();
12851
+ globalTelemetryService = null;
12852
+ }
12853
+ }
12854
+
12855
+ // src/LicensedRetrivora.ts
12856
+ var LicensedRetrivora = class {
12857
+ constructor(options) {
12858
+ this.initialized = false;
12859
+ this.licenseKey = options.licenseKey;
12860
+ this.projectId = options.projectId;
12861
+ if (options.enableTelemetry !== false) {
12862
+ initializeTelemetryService(this.projectId, this.licenseKey, options.userTelemetryUrl);
12863
+ }
12864
+ }
12865
+ /**
12866
+ * Initialize the SDK by validating license and fetching config
12867
+ */
12868
+ generateId() {
12869
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
12870
+ }
12871
+ /**
12872
+ * Initialize the SDK by validating license and fetching config
12873
+ */
12874
+ async initialize() {
12875
+ if (this.initialized) {
12876
+ console.log("[LicensedRetrivora] Already initialized");
12877
+ return;
12878
+ }
12879
+ console.log("[LicensedRetrivora] Initializing with license key...");
12880
+ const operationId = this.generateId();
12881
+ try {
12882
+ const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } = await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
12883
+ const telemetry = getTelemetryService();
12884
+ if (telemetry) {
12885
+ telemetry.recordEvent({
12886
+ eventType: "configuration_loaded" /* CONFIGURATION_LOADED */,
12887
+ operationId,
12888
+ metadata: {
12889
+ tier: tierConfig.tier,
12890
+ llmModel: tierConfig.llmModel,
12891
+ embeddingModel: tierConfig.embeddingModel,
12892
+ vectorDb: tierConfig.vectorDb.provider
12893
+ }
12894
+ });
12895
+ }
12896
+ this.ragConfig = {
12897
+ projectId: this.projectId,
12898
+ licenseKey: this.licenseKey,
12899
+ llm: llmConfig,
12900
+ embedding: embeddingConfig,
12901
+ vectorDb: vectorDbConfig,
12902
+ rag: {
12903
+ topK: tierConfig.topK,
12904
+ chunkSize: tierConfig.chunkSize,
12905
+ chunkOverlap: tierConfig.chunkOverlap,
12906
+ scoreThreshold: 0
12907
+ },
12908
+ telemetry: {
12909
+ enabled: true,
12910
+ url: "https://www.retrivora.com/api/telemetry"
12911
+ }
12912
+ };
12913
+ this.pipeline = new Pipeline(this.ragConfig);
12914
+ await this.pipeline.initialize();
12915
+ this.initialized = true;
12916
+ console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
12917
+ } catch (error) {
12918
+ const telemetry = getTelemetryService();
12919
+ if (telemetry && error instanceof Error) {
12920
+ telemetry.recordError(error, { operationId });
12921
+ await telemetry.flush();
12922
+ }
12923
+ throw error;
12924
+ }
12925
+ }
12926
+ /**
12927
+ * Ingest documents (upload files to vector database)
12928
+ * Returns success/failure status to end-user
12929
+ */
12930
+ async ingest(documents) {
12931
+ if (!this.initialized || !this.pipeline) {
12932
+ throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
12933
+ }
12934
+ const operationId = this.generateId();
12935
+ const telemetry = getTelemetryService();
12936
+ const startTime = Date.now();
12937
+ try {
12938
+ console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
12939
+ const results = await this.pipeline.ingest(documents);
12940
+ const durationMs = Date.now() - startTime;
12941
+ if (telemetry) {
12942
+ for (const result of results) {
12943
+ telemetry.recordDocumentIngested({
12944
+ documentId: String(result.docId),
12945
+ documentName: String(result.docId),
12946
+ documentSize: 0,
12947
+ // TODO: track actual size
12948
+ chunksGenerated: result.chunksIngested,
12949
+ durationMs
12950
+ });
12951
+ }
12952
+ }
12953
+ const successCount = results.length;
12954
+ return {
12955
+ success: successCount > 0,
12956
+ message: `Successfully ingested ${successCount} document(s). Data is now available for search.`,
12957
+ documentIds: results.map((r) => String(r.docId))
12958
+ };
12959
+ } catch (error) {
12960
+ const durationMs = Date.now() - startTime;
12961
+ if (telemetry && error instanceof Error) {
12962
+ telemetry.recordError(error, { operationId, durationMs });
12963
+ await telemetry.flush();
12964
+ }
12965
+ console.error("[LicensedRetrivora] Ingestion failed:", error);
12966
+ throw error;
12967
+ }
12968
+ }
12969
+ /**
12970
+ * Execute a user query and get response
12971
+ * Returns only the response text and sources (abstracted from underlying models)
12972
+ */
12973
+ async query(queryText, options) {
12974
+ var _a3;
12975
+ if (!this.initialized || !this.pipeline) {
12976
+ throw new Error("[LicensedRetrivora] SDK not initialized. Call initialize() first.");
12977
+ }
12978
+ const operationId = this.generateId();
12979
+ const telemetry = getTelemetryService();
12980
+ const startTime = Date.now();
12981
+ try {
12982
+ console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
12983
+ const response = await this.pipeline.runNormalQuery(queryText);
12984
+ const durationMs = Date.now() - startTime;
12985
+ if (telemetry) {
12986
+ telemetry.recordQueryExecuted({
12987
+ queryText,
12988
+ resultCount: ((_a3 = response.sources) == null ? void 0 : _a3.length) || 0,
12989
+ durationMs,
12990
+ operationId
12991
+ });
12992
+ }
12993
+ return {
12994
+ reply: response.reply,
12995
+ sources: response.sources
12996
+ };
12997
+ } catch (error) {
12998
+ const durationMs = Date.now() - startTime;
12999
+ if (telemetry && error instanceof Error) {
13000
+ telemetry.recordError(error, { operationId, durationMs });
13001
+ await telemetry.flush();
13002
+ }
13003
+ console.error("[LicensedRetrivora] Query failed:", error);
13004
+ throw error;
13005
+ }
13006
+ }
13007
+ /**
13008
+ * Get license tier information (for UI display if needed)
13009
+ */
13010
+ async getTierInfo() {
13011
+ if (!this.ragConfig) {
13012
+ throw new Error("[LicensedRetrivora] SDK not initialized.");
13013
+ }
13014
+ return {
13015
+ tier: "Standard",
13016
+ // TODO: fetch from tier config
13017
+ model: this.ragConfig.llm.model,
13018
+ embeddingModel: this.ragConfig.embedding.model
13019
+ };
13020
+ }
13021
+ /**
13022
+ * Cleanup and shutdown
13023
+ */
13024
+ async shutdown() {
13025
+ await shutdownTelemetryService();
13026
+ this.initialized = false;
13027
+ console.log("[LicensedRetrivora] Shutdown complete");
13028
+ }
13029
+ /**
13030
+ * Check if SDK is initialized
13031
+ */
13032
+ isInitialized() {
13033
+ return this.initialized;
13034
+ }
13035
+ /**
13036
+ * Get current RAG configuration (for debugging)
13037
+ */
13038
+ getConfig() {
13039
+ return this.ragConfig;
13040
+ }
13041
+ };
13042
+ async function createRetrivora(options) {
13043
+ const retrivora = new LicensedRetrivora(options);
13044
+ await retrivora.initialize();
13045
+ return retrivora;
13046
+ }
12389
13047
  // Annotate the CommonJS export names for ESM import in node:
12390
13048
  0 && (module.exports = {
12391
13049
  AnthropicProvider,
@@ -12405,13 +13063,16 @@ var LicenseValidator = _LicenseValidator;
12405
13063
  EmbeddingFailedException,
12406
13064
  EmbeddingStrategy,
12407
13065
  EmbeddingStrategyResolver,
13066
+ EventType,
12408
13067
  GroqProvider,
12409
13068
  IntentClassifier,
12410
13069
  LLMFactory,
12411
13070
  LLM_PROFILES,
13071
+ LicenseConfigResolver,
12412
13072
  LicenseValidationError,
12413
13073
  LicenseValidator,
12414
13074
  LicenseVerifier,
13075
+ LicensedRetrivora,
12415
13076
  MilvusProvider,
12416
13077
  MixedRendererStrategy,
12417
13078
  MongoDBProvider,
@@ -12444,6 +13105,7 @@ var LicenseValidator = _LicenseValidator;
12444
13105
  SDKVersionUnsupportedError,
12445
13106
  SDK_VERSION,
12446
13107
  TableRendererStrategy,
13108
+ TelemetryService,
12447
13109
  TextRendererStrategy,
12448
13110
  UniversalLLMAdapter,
12449
13111
  UniversalVectorProvider,
@@ -12459,13 +13121,19 @@ var LicenseValidator = _LicenseValidator;
12459
13121
  createHistoryHandler,
12460
13122
  createIngestHandler,
12461
13123
  createRagHandler,
13124
+ createRetrivora,
12462
13125
  createSessionsHandler,
12463
13126
  createStreamHandler,
12464
13127
  createUploadHandler,
12465
13128
  decideVisualization,
12466
13129
  getRagConfig,
13130
+ getRuntimeConfig,
13131
+ getTelemetryService,
13132
+ initializeTelemetryService,
13133
+ injectRuntimeConfig,
12467
13134
  normalizeProjectSettings,
12468
13135
  projectSettingsToUiConfig,
13136
+ shutdownTelemetryService,
12469
13137
  sseErrorFrame,
12470
13138
  sseFrame,
12471
13139
  sseMetaFrame,