@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CSSProperties, MouseEvent, ReactNode, ElementType } from 'react';
|
|
2
|
-
import { W as WidgetPosition, Z as Product, s as UIConfig, P as ProjectChatSettings, o as RagMessage, w as VectorMatch, J as UITransformationResponse, n as RagConfig, I as ILLMProvider, f as IngestDocument, C as ChatMessage, c as ChatResponse, _ as RetrievalResult, t as UniversalRagConfig } from './ILLMProvider-B8TAVx3j.mjs';
|
|
2
|
+
import { W as WidgetPosition, Z as Product, s as UIConfig, P as ProjectChatSettings, o as RagMessage, w as VectorMatch, L as LLMConfig, d as EmbeddingConfig, V as VectorDBConfig, J as UITransformationResponse, n as RagConfig, I as ILLMProvider, f as IngestDocument, C as ChatMessage, c as ChatResponse, _ as RetrievalResult, t as UniversalRagConfig } from './ILLMProvider-B8TAVx3j.mjs';
|
|
3
3
|
|
|
4
4
|
interface ArchitectureCardProps {
|
|
5
5
|
icon: ReactNode;
|
|
@@ -219,6 +219,104 @@ declare class ConfigFetcher {
|
|
|
219
219
|
static fetchRemoteVectorConfig(projectId: string, licenseKey?: string): Promise<RemoteVectorConfig | null>;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* LicenseConfigResolver — Resolves LLM and embedding configuration
|
|
224
|
+
* based on the user's license tier from Retrivora admin dashboard.
|
|
225
|
+
*
|
|
226
|
+
* The end-user SDK only needs:
|
|
227
|
+
* - licenseKey (JWT token from Retrivora)
|
|
228
|
+
* - projectId (workspace identifier)
|
|
229
|
+
*
|
|
230
|
+
* Configuration includes:
|
|
231
|
+
* 1. Tier-based model selection (/api/v1/config)
|
|
232
|
+
* 2. Provider API credentials (/api/v1/credentials)
|
|
233
|
+
* 3. Vector DB and rate limit settings
|
|
234
|
+
*
|
|
235
|
+
* All provider API keys (Gemini, Groq, Pinecone) are stored on Retrivora backend
|
|
236
|
+
* and never exposed to end-users directly.
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
interface LicenseTierConfig {
|
|
240
|
+
tier: 'free_trial' | 'free' | 'hobby' | 'pro' | 'enterprise';
|
|
241
|
+
llmModel: string;
|
|
242
|
+
embeddingModel: string;
|
|
243
|
+
embeddingDimensions: number;
|
|
244
|
+
maxTokens: number;
|
|
245
|
+
chunkSize: number;
|
|
246
|
+
chunkOverlap: number;
|
|
247
|
+
topK: number;
|
|
248
|
+
vectorDb: {
|
|
249
|
+
provider: string;
|
|
250
|
+
indexName: string;
|
|
251
|
+
};
|
|
252
|
+
rateLimit?: {
|
|
253
|
+
requestsPerMinute: number;
|
|
254
|
+
tokensPerDay: number;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
interface ProviderCredentials {
|
|
258
|
+
geminiApiKey?: string;
|
|
259
|
+
groqApiKey?: string;
|
|
260
|
+
pineconeApiKey?: string;
|
|
261
|
+
textEmbeddingProvider?: string;
|
|
262
|
+
}
|
|
263
|
+
interface ProviderCredentials {
|
|
264
|
+
geminiApiKey?: string;
|
|
265
|
+
groqApiKey?: string;
|
|
266
|
+
pineconeApiKey?: string;
|
|
267
|
+
textEmbeddingProvider?: string;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Resolver for license-based configuration.
|
|
271
|
+
* This is called by the end-user SDK after they instantiate with licenseKey + projectId.
|
|
272
|
+
*/
|
|
273
|
+
declare class LicenseConfigResolver {
|
|
274
|
+
private static readonly RETRIVORA_CONFIG_URL;
|
|
275
|
+
private static readonly RETRIVORA_CREDENTIALS_URL;
|
|
276
|
+
private static readonly CACHE_TTL_MS;
|
|
277
|
+
private static configCache;
|
|
278
|
+
/**
|
|
279
|
+
* Validate and resolve configuration from license key
|
|
280
|
+
* @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
|
|
281
|
+
* @param projectId Workspace identifier
|
|
282
|
+
* @returns Resolved LLM and embedding configs with provider credentials
|
|
283
|
+
*/
|
|
284
|
+
static resolveFromLicense(licenseKey: string, projectId: string): Promise<{
|
|
285
|
+
llmConfig: LLMConfig;
|
|
286
|
+
embeddingConfig: EmbeddingConfig;
|
|
287
|
+
vectorDbConfig: VectorDBConfig;
|
|
288
|
+
tierConfig: LicenseTierConfig;
|
|
289
|
+
credentials: ProviderCredentials;
|
|
290
|
+
}>;
|
|
291
|
+
/**
|
|
292
|
+
* Fetch tier configuration from Retrivora config API
|
|
293
|
+
*/
|
|
294
|
+
private static fetchTierConfig;
|
|
295
|
+
/**
|
|
296
|
+
* Fetch provider credentials from Retrivora credentials API
|
|
297
|
+
*/
|
|
298
|
+
private static fetchProviderCredentials;
|
|
299
|
+
/**
|
|
300
|
+
* Build LLM, embedding, and vector DB configs from tier and credentials
|
|
301
|
+
*/
|
|
302
|
+
private static buildConfigs;
|
|
303
|
+
/**
|
|
304
|
+
* Get provider-specific vector DB options
|
|
305
|
+
*/
|
|
306
|
+
private static getVectorDbOptions;
|
|
307
|
+
/**
|
|
308
|
+
* Clear configuration cache (useful for testing or manual refresh)
|
|
309
|
+
*/
|
|
310
|
+
static clearCache(): void;
|
|
311
|
+
/**
|
|
312
|
+
* Get cache stats for debugging
|
|
313
|
+
*/
|
|
314
|
+
static getCacheStats(): {
|
|
315
|
+
size: number;
|
|
316
|
+
entries: string[];
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
222
320
|
/**
|
|
223
321
|
* Primary rendering outcome types supported by the decision engine.
|
|
224
322
|
*/
|
|
@@ -661,4 +759,4 @@ declare class BatchProcessor {
|
|
|
661
759
|
static processConcurrent<T, R>(items: T[], processor: (item: T) => Promise<R>, concurrency?: number, options?: BatchOptions): Promise<BatchResult<R>>;
|
|
662
760
|
}
|
|
663
761
|
|
|
664
|
-
export { AuthenticationException as A, type BatchOptions as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E,
|
|
762
|
+
export { wrapError as $, AuthenticationException as A, type BatchOptions as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, RetrievalException as F, Retrivora as G, RetrivoraError as H, type IRenderRule as I, type RetrivoraErrorCode as J, SDKVersionUnsupportedError as K, type LicenseTierConfig as L, type MessageBubbleProps as M, SDK_VERSION as N, isTransientError as O, type ProductCardProps as P, type ArchitectureCardProps as Q, type RemoteConfig as R, type SourceCardProps as S, type ChatViewportSize as T, DocumentChunker as U, LicenseConfigResolver as V, Pipeline as W, type PipelineStep as X, type ProviderPill as Y, type RenderSectionDecision as Z, type Snippet as _, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, BatchProcessor as e, type BatchResult as f, type ChartType as g, type Chunk as h, type ChunkOptions as i, ConfigFetcher as j, ConfigurationException as k, type DecisionContext as l, type IRendererStrategy as m, type IntentCategory as n, LicenseValidationError as o, type LicenseValidationRequest as p, type LicenseValidationResponse as q, LicenseValidator as r, type ProviderCredentials as s, ProviderNotFoundException as t, RateLimitException as u, type RemoteEmbeddingConfig as v, type RemoteLLMConfig as w, type RemoteVectorConfig as x, type RenderDecision as y, type RenderType as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CSSProperties, MouseEvent, ReactNode, ElementType } from 'react';
|
|
2
|
-
import { W as WidgetPosition, Z as Product, s as UIConfig, P as ProjectChatSettings, o as RagMessage, w as VectorMatch, J as UITransformationResponse, n as RagConfig, I as ILLMProvider, f as IngestDocument, C as ChatMessage, c as ChatResponse, _ as RetrievalResult, t as UniversalRagConfig } from './ILLMProvider-B8TAVx3j.js';
|
|
2
|
+
import { W as WidgetPosition, Z as Product, s as UIConfig, P as ProjectChatSettings, o as RagMessage, w as VectorMatch, L as LLMConfig, d as EmbeddingConfig, V as VectorDBConfig, J as UITransformationResponse, n as RagConfig, I as ILLMProvider, f as IngestDocument, C as ChatMessage, c as ChatResponse, _ as RetrievalResult, t as UniversalRagConfig } from './ILLMProvider-B8TAVx3j.js';
|
|
3
3
|
|
|
4
4
|
interface ArchitectureCardProps {
|
|
5
5
|
icon: ReactNode;
|
|
@@ -219,6 +219,104 @@ declare class ConfigFetcher {
|
|
|
219
219
|
static fetchRemoteVectorConfig(projectId: string, licenseKey?: string): Promise<RemoteVectorConfig | null>;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* LicenseConfigResolver — Resolves LLM and embedding configuration
|
|
224
|
+
* based on the user's license tier from Retrivora admin dashboard.
|
|
225
|
+
*
|
|
226
|
+
* The end-user SDK only needs:
|
|
227
|
+
* - licenseKey (JWT token from Retrivora)
|
|
228
|
+
* - projectId (workspace identifier)
|
|
229
|
+
*
|
|
230
|
+
* Configuration includes:
|
|
231
|
+
* 1. Tier-based model selection (/api/v1/config)
|
|
232
|
+
* 2. Provider API credentials (/api/v1/credentials)
|
|
233
|
+
* 3. Vector DB and rate limit settings
|
|
234
|
+
*
|
|
235
|
+
* All provider API keys (Gemini, Groq, Pinecone) are stored on Retrivora backend
|
|
236
|
+
* and never exposed to end-users directly.
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
interface LicenseTierConfig {
|
|
240
|
+
tier: 'free_trial' | 'free' | 'hobby' | 'pro' | 'enterprise';
|
|
241
|
+
llmModel: string;
|
|
242
|
+
embeddingModel: string;
|
|
243
|
+
embeddingDimensions: number;
|
|
244
|
+
maxTokens: number;
|
|
245
|
+
chunkSize: number;
|
|
246
|
+
chunkOverlap: number;
|
|
247
|
+
topK: number;
|
|
248
|
+
vectorDb: {
|
|
249
|
+
provider: string;
|
|
250
|
+
indexName: string;
|
|
251
|
+
};
|
|
252
|
+
rateLimit?: {
|
|
253
|
+
requestsPerMinute: number;
|
|
254
|
+
tokensPerDay: number;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
interface ProviderCredentials {
|
|
258
|
+
geminiApiKey?: string;
|
|
259
|
+
groqApiKey?: string;
|
|
260
|
+
pineconeApiKey?: string;
|
|
261
|
+
textEmbeddingProvider?: string;
|
|
262
|
+
}
|
|
263
|
+
interface ProviderCredentials {
|
|
264
|
+
geminiApiKey?: string;
|
|
265
|
+
groqApiKey?: string;
|
|
266
|
+
pineconeApiKey?: string;
|
|
267
|
+
textEmbeddingProvider?: string;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Resolver for license-based configuration.
|
|
271
|
+
* This is called by the end-user SDK after they instantiate with licenseKey + projectId.
|
|
272
|
+
*/
|
|
273
|
+
declare class LicenseConfigResolver {
|
|
274
|
+
private static readonly RETRIVORA_CONFIG_URL;
|
|
275
|
+
private static readonly RETRIVORA_CREDENTIALS_URL;
|
|
276
|
+
private static readonly CACHE_TTL_MS;
|
|
277
|
+
private static configCache;
|
|
278
|
+
/**
|
|
279
|
+
* Validate and resolve configuration from license key
|
|
280
|
+
* @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
|
|
281
|
+
* @param projectId Workspace identifier
|
|
282
|
+
* @returns Resolved LLM and embedding configs with provider credentials
|
|
283
|
+
*/
|
|
284
|
+
static resolveFromLicense(licenseKey: string, projectId: string): Promise<{
|
|
285
|
+
llmConfig: LLMConfig;
|
|
286
|
+
embeddingConfig: EmbeddingConfig;
|
|
287
|
+
vectorDbConfig: VectorDBConfig;
|
|
288
|
+
tierConfig: LicenseTierConfig;
|
|
289
|
+
credentials: ProviderCredentials;
|
|
290
|
+
}>;
|
|
291
|
+
/**
|
|
292
|
+
* Fetch tier configuration from Retrivora config API
|
|
293
|
+
*/
|
|
294
|
+
private static fetchTierConfig;
|
|
295
|
+
/**
|
|
296
|
+
* Fetch provider credentials from Retrivora credentials API
|
|
297
|
+
*/
|
|
298
|
+
private static fetchProviderCredentials;
|
|
299
|
+
/**
|
|
300
|
+
* Build LLM, embedding, and vector DB configs from tier and credentials
|
|
301
|
+
*/
|
|
302
|
+
private static buildConfigs;
|
|
303
|
+
/**
|
|
304
|
+
* Get provider-specific vector DB options
|
|
305
|
+
*/
|
|
306
|
+
private static getVectorDbOptions;
|
|
307
|
+
/**
|
|
308
|
+
* Clear configuration cache (useful for testing or manual refresh)
|
|
309
|
+
*/
|
|
310
|
+
static clearCache(): void;
|
|
311
|
+
/**
|
|
312
|
+
* Get cache stats for debugging
|
|
313
|
+
*/
|
|
314
|
+
static getCacheStats(): {
|
|
315
|
+
size: number;
|
|
316
|
+
entries: string[];
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
222
320
|
/**
|
|
223
321
|
* Primary rendering outcome types supported by the decision engine.
|
|
224
322
|
*/
|
|
@@ -661,4 +759,4 @@ declare class BatchProcessor {
|
|
|
661
759
|
static processConcurrent<T, R>(items: T[], processor: (item: T) => Promise<R>, concurrency?: number, options?: BatchOptions): Promise<BatchResult<R>>;
|
|
662
760
|
}
|
|
663
761
|
|
|
664
|
-
export { AuthenticationException as A, type BatchOptions as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E,
|
|
762
|
+
export { wrapError as $, AuthenticationException as A, type BatchOptions as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, RetrievalException as F, Retrivora as G, RetrivoraError as H, type IRenderRule as I, type RetrivoraErrorCode as J, SDKVersionUnsupportedError as K, type LicenseTierConfig as L, type MessageBubbleProps as M, SDK_VERSION as N, isTransientError as O, type ProductCardProps as P, type ArchitectureCardProps as Q, type RemoteConfig as R, type SourceCardProps as S, type ChatViewportSize as T, DocumentChunker as U, LicenseConfigResolver as V, Pipeline as W, type PipelineStep as X, type ProviderPill as Y, type RenderSectionDecision as Z, type Snippet as _, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, BatchProcessor as e, type BatchResult as f, type ChartType as g, type Chunk as h, type ChunkOptions as i, ConfigFetcher as j, ConfigurationException as k, type DecisionContext as l, type IRendererStrategy as m, type IntentCategory as n, LicenseValidationError as o, type LicenseValidationRequest as p, type LicenseValidationResponse as q, LicenseValidator as r, type ProviderCredentials as s, ProviderNotFoundException as t, RateLimitException as u, type RemoteEmbeddingConfig as v, type RemoteLLMConfig as w, type RemoteVectorConfig as x, type RenderDecision as y, type RenderType as z };
|
package/dist/handlers/index.js
CHANGED
|
@@ -317,7 +317,7 @@ var init_package = __esm({
|
|
|
317
317
|
"package.json"() {
|
|
318
318
|
package_default = {
|
|
319
319
|
name: "@retrivora-ai/rag-engine",
|
|
320
|
-
version: "2.3.
|
|
320
|
+
version: "2.3.7",
|
|
321
321
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
322
322
|
author: "Abhinav Alkuchi",
|
|
323
323
|
license: "UNLICENSED",
|
|
@@ -2849,13 +2849,13 @@ LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
|
2849
2849
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
2850
2850
|
// Rotate this key only when the signing private key is replaced.
|
|
2851
2851
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2852
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2853
|
+
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2854
|
+
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2855
|
+
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2856
|
+
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2857
|
+
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2858
|
+
6QIDAQAB
|
|
2859
2859
|
-----END PUBLIC KEY-----`;
|
|
2860
2860
|
|
|
2861
2861
|
// src/config/constants.ts
|
|
@@ -2904,6 +2904,7 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
2904
2904
|
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
2905
2905
|
|
|
2906
2906
|
// src/config/serverConfig.ts
|
|
2907
|
+
var _runtimeConfig = null;
|
|
2907
2908
|
function readString(env, name) {
|
|
2908
2909
|
var _a3;
|
|
2909
2910
|
const value = (_a3 = env[name]) == null ? void 0 : _a3.trim();
|
|
@@ -2927,7 +2928,7 @@ function readEnum(env, name, fallback, allowed) {
|
|
|
2927
2928
|
throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(", ")}`);
|
|
2928
2929
|
}
|
|
2929
2930
|
function getEnvConfig(env = process.env, base) {
|
|
2930
|
-
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb
|
|
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;
|
|
2931
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;
|
|
2932
2933
|
const jwtProjectId = (() => {
|
|
2933
2934
|
if (!licenseKey) return void 0;
|
|
@@ -3019,25 +3020,35 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3019
3020
|
return true;
|
|
3020
3021
|
}
|
|
3021
3022
|
})();
|
|
3022
|
-
const
|
|
3023
|
-
const
|
|
3024
|
-
const
|
|
3025
|
-
const
|
|
3026
|
-
const
|
|
3027
|
-
const
|
|
3028
|
-
const
|
|
3029
|
-
const
|
|
3030
|
-
const
|
|
3031
|
-
const
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
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";
|
|
3035
3046
|
return __spreadProps(__spreadValues({
|
|
3036
3047
|
projectId,
|
|
3037
3048
|
licenseKey,
|
|
3038
3049
|
vectorDb: {
|
|
3039
3050
|
provider: vectorProvider,
|
|
3040
|
-
indexName: (
|
|
3051
|
+
indexName: (_fb = (_eb = readString(env, "VECTOR_DB_INDEX")) != null ? _eb : vectorDbOptions.indexName) != null ? _fb : "rag-index",
|
|
3041
3052
|
options: vectorDbOptions
|
|
3042
3053
|
},
|
|
3043
3054
|
llm: {
|
|
@@ -3067,30 +3078,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3067
3078
|
}
|
|
3068
3079
|
},
|
|
3069
3080
|
ui: {
|
|
3070
|
-
title: (
|
|
3071
|
-
subtitle: (
|
|
3072
|
-
primaryColor: (
|
|
3073
|
-
accentColor: (
|
|
3074
|
-
logoUrl: (
|
|
3075
|
-
placeholder: (
|
|
3076
|
-
showSources: ((
|
|
3077
|
-
welcomeMessage: (
|
|
3078
|
-
visualStyle: (
|
|
3079
|
-
borderRadius: (
|
|
3080
|
-
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"
|
|
3081
3092
|
},
|
|
3082
3093
|
rag: {
|
|
3083
3094
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3084
3095
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3085
3096
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3086
3097
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3087
|
-
filterableFields: (
|
|
3098
|
+
filterableFields: (_Bb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Bb.split(",").map((f) => f.trim()),
|
|
3088
3099
|
// Query pipeline toggles — read from .env.local
|
|
3089
3100
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3090
3101
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3091
3102
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3092
|
-
architecture: (
|
|
3093
|
-
chunkingStrategy: (
|
|
3103
|
+
architecture: (_Cb = readString(env, "RAG_ARCHITECTURE")) != null ? _Cb : "simple",
|
|
3104
|
+
chunkingStrategy: (_Db = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Db : "recursive",
|
|
3094
3105
|
uiMapping: (() => {
|
|
3095
3106
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3096
3107
|
if (!raw) return void 0;
|
|
@@ -3103,7 +3114,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3103
3114
|
},
|
|
3104
3115
|
telemetry: {
|
|
3105
3116
|
enabled: telemetryEnabled,
|
|
3106
|
-
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"
|
|
3107
3118
|
}
|
|
3108
3119
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3109
3120
|
graphDb: {
|
|
@@ -4421,7 +4432,7 @@ var UniversalLLMAdapter = class {
|
|
|
4421
4432
|
});
|
|
4422
4433
|
}
|
|
4423
4434
|
async chat(messages, context) {
|
|
4424
|
-
var _a3, _b, _c, _d, _e;
|
|
4435
|
+
var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j;
|
|
4425
4436
|
const path2 = (_a3 = this.opts.chatPath) != null ? _a3 : "/chat/completions";
|
|
4426
4437
|
const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
|
|
4427
4438
|
role: m.role || "user",
|
|
@@ -4451,16 +4462,27 @@ ${context != null ? context : "None"}` },
|
|
|
4451
4462
|
};
|
|
4452
4463
|
}
|
|
4453
4464
|
try {
|
|
4465
|
+
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path2}`);
|
|
4466
|
+
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
4467
|
+
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${((_b = this.apiKey) == null ? void 0 : _b.substring(0, 20)) || "none"}...`);
|
|
4454
4468
|
const { data: data2 } = await this.http.post(path2, payload);
|
|
4455
|
-
const extractPath2 = (
|
|
4456
|
-
const result2 = (
|
|
4469
|
+
const extractPath2 = (_c = this.opts.responseExtractPath) != null ? _c : "choices[0].message.content";
|
|
4470
|
+
const result2 = (_d = resolvePath(data2, extractPath2)) != null ? _d : extractContent(data2);
|
|
4457
4471
|
if (result2 !== void 0) {
|
|
4458
4472
|
return String(result2);
|
|
4459
4473
|
}
|
|
4460
4474
|
} catch (httpErr) {
|
|
4461
|
-
|
|
4462
|
-
|
|
4475
|
+
console.error("[UniversalLLMAdapter] \u274C HTTP chat request failed:", {
|
|
4476
|
+
status: (_e = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _e.status,
|
|
4477
|
+
statusText: (_f = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _f.statusText,
|
|
4478
|
+
url: (_g2 = httpErr == null ? void 0 : httpErr.config) == null ? void 0 : _g2.url,
|
|
4479
|
+
errorData: (_h = httpErr == null ? void 0 : httpErr.response) == null ? void 0 : _h.data,
|
|
4480
|
+
message: httpErr == null ? void 0 : httpErr.message
|
|
4481
|
+
});
|
|
4482
|
+
const _g3 = globalThis;
|
|
4483
|
+
const dispatch = _g3.__retrivoraDispatchChat;
|
|
4463
4484
|
if (typeof dispatch === "function") {
|
|
4485
|
+
console.debug("[UniversalLLMAdapter] \u{1F504} Attempting in-process fallback dispatch");
|
|
4464
4486
|
const res = await dispatch({
|
|
4465
4487
|
model: this.model,
|
|
4466
4488
|
messages: formattedMessages,
|
|
@@ -4475,8 +4497,8 @@ ${context != null ? context : "None"}` },
|
|
|
4475
4497
|
throw httpErr;
|
|
4476
4498
|
}
|
|
4477
4499
|
const { data } = await this.http.post(path2, payload);
|
|
4478
|
-
const extractPath = (
|
|
4479
|
-
const result = (
|
|
4500
|
+
const extractPath = (_i = this.opts.responseExtractPath) != null ? _i : "choices[0].message.content";
|
|
4501
|
+
const result = (_j = resolvePath(data, extractPath)) != null ? _j : extractContent(data);
|
|
4480
4502
|
if (result === void 0) {
|
|
4481
4503
|
throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
|
|
4482
4504
|
}
|
|
@@ -4615,36 +4637,70 @@ ${context != null ? context : "None"}` },
|
|
|
4615
4637
|
});
|
|
4616
4638
|
}
|
|
4617
4639
|
async embed(text) {
|
|
4618
|
-
var _a3, _b, _c, _d, _e;
|
|
4640
|
+
var _a3, _b, _c, _d, _e, _f, _g2;
|
|
4619
4641
|
const path2 = (_a3 = this.opts.embedPath) != null ? _a3 : "/embeddings";
|
|
4620
4642
|
const payload = this.opts.embedPayloadTemplate ? buildPayload(this.opts.embedPayloadTemplate, { input: text, model: this.model }) : { input: text, model: this.model };
|
|
4621
4643
|
try {
|
|
4622
|
-
const { data
|
|
4623
|
-
const
|
|
4624
|
-
const
|
|
4625
|
-
if (Array.isArray(
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4644
|
+
const { data } = await this.http.post(path2, payload);
|
|
4645
|
+
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
4646
|
+
const vector = resolvePath(data, extractPath);
|
|
4647
|
+
if (Array.isArray(vector)) return vector;
|
|
4648
|
+
console.warn(
|
|
4649
|
+
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
4650
|
+
data
|
|
4651
|
+
);
|
|
4652
|
+
} catch (err) {
|
|
4653
|
+
console.warn(
|
|
4654
|
+
`[UniversalLLMAdapter] HTTP embedding request failed: ${(err == null ? void 0 : err.message) || err}`,
|
|
4655
|
+
{ path: path2, model: this.model }
|
|
4656
|
+
);
|
|
4657
|
+
const _g3 = globalThis;
|
|
4658
|
+
const dispatchEmbed = _g3.__retrivoraDispatchEmbedding;
|
|
4629
4659
|
if (typeof dispatchEmbed === "function") {
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4660
|
+
try {
|
|
4661
|
+
const res = await dispatchEmbed({ input: text, model: this.model }, this.apiKey);
|
|
4662
|
+
if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
|
|
4663
|
+
return res.data[0].embedding;
|
|
4664
|
+
}
|
|
4665
|
+
} catch (dispatchErr) {
|
|
4666
|
+
console.warn("[UniversalLLMAdapter] In-process dispatch embedding failed:", dispatchErr);
|
|
4633
4667
|
}
|
|
4634
4668
|
}
|
|
4635
4669
|
}
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4670
|
+
try {
|
|
4671
|
+
const { data } = await this.http.post(path2, payload);
|
|
4672
|
+
const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
|
|
4673
|
+
const vector = resolvePath(data, extractPath);
|
|
4674
|
+
if (Array.isArray(vector)) {
|
|
4675
|
+
return vector;
|
|
4676
|
+
}
|
|
4677
|
+
console.error(
|
|
4678
|
+
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
4679
|
+
data
|
|
4680
|
+
);
|
|
4681
|
+
throw new Error(
|
|
4682
|
+
`[UniversalLLMAdapter] Could not extract embedding vector. Expected array at '${extractPath}', got: ${typeof vector}. Response keys: ${Object.keys(data || {})}.`
|
|
4683
|
+
);
|
|
4684
|
+
} catch (err) {
|
|
4685
|
+
console.error(
|
|
4686
|
+
`[UniversalLLMAdapter] Both embedding attempts failed. Path: ${path2}, Model: ${this.model}`,
|
|
4687
|
+
{ 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 }
|
|
4688
|
+
);
|
|
4689
|
+
throw new Error(
|
|
4690
|
+
`[UniversalLLMAdapter] Failed to generate embedding after 2 attempts: ${(err == null ? void 0 : err.message) || err}`
|
|
4691
|
+
);
|
|
4641
4692
|
}
|
|
4642
|
-
return vector;
|
|
4643
4693
|
}
|
|
4644
4694
|
async batchEmbed(texts) {
|
|
4645
4695
|
const results = [];
|
|
4646
4696
|
for (const text of texts) {
|
|
4647
|
-
|
|
4697
|
+
try {
|
|
4698
|
+
const vector = await this.embed(text);
|
|
4699
|
+
results.push(vector);
|
|
4700
|
+
} catch (err) {
|
|
4701
|
+
console.warn(`[UniversalLLMAdapter] batchEmbed failed for text (first 50 chars): ${text.slice(0, 50)}...`, err);
|
|
4702
|
+
throw err;
|
|
4703
|
+
}
|
|
4648
4704
|
}
|
|
4649
4705
|
return results;
|
|
4650
4706
|
}
|
|
@@ -11377,6 +11433,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11377
11433
|
const plugin = getOrCreatePlugin(configOrPlugin);
|
|
11378
11434
|
const onAuthorize = options == null ? void 0 : options.onAuthorize;
|
|
11379
11435
|
return async function POST(req, context) {
|
|
11436
|
+
console.log("Upload handler invoked");
|
|
11380
11437
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11381
11438
|
if (authResult) return authResult;
|
|
11382
11439
|
const config = plugin.getConfig();
|
|
@@ -11385,6 +11442,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11385
11442
|
try {
|
|
11386
11443
|
const formData = await req.formData();
|
|
11387
11444
|
const files = formData.getAll("files");
|
|
11445
|
+
console.log("Files received for upload:", files.map((f) => f.name));
|
|
11388
11446
|
const namespace = formData.get("namespace") || void 0;
|
|
11389
11447
|
const dimensionRaw = formData.get("dimension");
|
|
11390
11448
|
const dimension = dimensionRaw ? parseInt(dimensionRaw, 10) : void 0;
|