@retrivora-ai/rag-engine 2.4.2 → 2.4.5

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.
Files changed (140) hide show
  1. package/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-Csy_K1qQ.d.mts} +2 -0
  2. package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-Dg18zZGk.d.ts} +2 -0
  3. package/dist/handlers/index.js +31 -5
  4. package/dist/handlers/index.mjs +31 -5
  5. package/dist/index.d.mts +3 -3
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +41 -21
  8. package/dist/index.min.css +2 -0
  9. package/dist/index.mjs +41 -21
  10. package/dist/server.d.mts +2 -2
  11. package/dist/server.d.ts +2 -2
  12. package/dist/server.js +32 -5
  13. package/dist/server.mjs +32 -5
  14. package/package.json +5 -4
  15. package/src/LicensedRetrivora.ts +0 -278
  16. package/src/app/api/chat/route.ts +0 -4
  17. package/src/app/api/health/route.ts +0 -5
  18. package/src/app/api/ingest/route.ts +0 -27
  19. package/src/app/api/suggestions/route.ts +0 -5
  20. package/src/app/api/upload/route.ts +0 -5
  21. package/src/app/constants.tsx +0 -270
  22. package/src/app/favicon.ico +0 -0
  23. package/src/app/globals.css +0 -449
  24. package/src/app/layout.tsx +0 -22
  25. package/src/app/page.tsx +0 -64
  26. package/src/app/types.ts +0 -30
  27. package/src/browser.tsx +0 -139
  28. package/src/components/ChatWidget.tsx +0 -393
  29. package/src/components/ChatWindow.tsx +0 -952
  30. package/src/components/CodeViewer.tsx +0 -56
  31. package/src/components/ConfigProvider.tsx +0 -123
  32. package/src/components/DocumentUpload.tsx +0 -354
  33. package/src/components/DynamicChart.tsx +0 -297
  34. package/src/components/HourglassLoader.tsx +0 -87
  35. package/src/components/MarkdownComponents.tsx +0 -186
  36. package/src/components/MessageBubble.tsx +0 -498
  37. package/src/components/ObservabilityPanel.tsx +0 -374
  38. package/src/components/ProductCard.tsx +0 -107
  39. package/src/components/ProductCarousel.tsx +0 -97
  40. package/src/components/SourceCard.tsx +0 -61
  41. package/src/components/ThemeProvider.tsx +0 -8
  42. package/src/components/ThemeToggle.tsx +0 -29
  43. package/src/components/ThinkingBlock.tsx +0 -75
  44. package/src/components/UIDispatcher.tsx +0 -342
  45. package/src/components/VisualizationRenderer.tsx +0 -621
  46. package/src/components/constants.tsx +0 -503
  47. package/src/config/ConfigBuilder.ts +0 -285
  48. package/src/config/EmbeddingStrategy.ts +0 -148
  49. package/src/config/LicenseConfigResolver.ts +0 -298
  50. package/src/config/RagConfig.ts +0 -328
  51. package/src/config/UniversalProfiles.ts +0 -82
  52. package/src/config/constants.ts +0 -64
  53. package/src/config/serverConfig.ts +0 -378
  54. package/src/config/uiConstants.ts +0 -47
  55. package/src/core/BatchProcessor.ts +0 -385
  56. package/src/core/CircuitBreaker.ts +0 -118
  57. package/src/core/ConfigFetcher.ts +0 -220
  58. package/src/core/ConfigResolver.ts +0 -165
  59. package/src/core/ConfigValidator.ts +0 -197
  60. package/src/core/DatabaseStorage.ts +0 -526
  61. package/src/core/FreeTierLimitsGuard.ts +0 -281
  62. package/src/core/LLMRouter.ts +0 -79
  63. package/src/core/LangChainAgent.ts +0 -132
  64. package/src/core/LicenseValidator.ts +0 -284
  65. package/src/core/LicenseVerifier.ts +0 -261
  66. package/src/core/MultiAgentCoordinator.ts +0 -239
  67. package/src/core/Pipeline.ts +0 -1279
  68. package/src/core/PluginManager.ts +0 -277
  69. package/src/core/ProjectSettings.ts +0 -247
  70. package/src/core/ProviderHealthCheck.ts +0 -133
  71. package/src/core/ProviderInterfaces.ts +0 -37
  72. package/src/core/ProviderRegistry.ts +0 -156
  73. package/src/core/QueryProcessor.ts +0 -399
  74. package/src/core/Retrivora.ts +0 -98
  75. package/src/core/VectorPlugin.ts +0 -193
  76. package/src/core/mcp.ts +0 -261
  77. package/src/exceptions/index.ts +0 -131
  78. package/src/handlers/index.ts +0 -1625
  79. package/src/hooks/useHydrated.ts +0 -13
  80. package/src/hooks/useProjectSettings.ts +0 -105
  81. package/src/hooks/useRagChat.ts +0 -436
  82. package/src/hooks/useStoredMessages.ts +0 -64
  83. package/src/index.css +0 -4269
  84. package/src/index.ts +0 -137
  85. package/src/lib/plugin.ts +0 -24
  86. package/src/llm/ILLMProvider.ts +0 -60
  87. package/src/llm/LLMFactory.ts +0 -141
  88. package/src/llm/providers/AnthropicProvider.ts +0 -215
  89. package/src/llm/providers/GeminiProvider.ts +0 -311
  90. package/src/llm/providers/GroqProvider.ts +0 -184
  91. package/src/llm/providers/OllamaProvider.ts +0 -232
  92. package/src/llm/providers/OpenAIProvider.ts +0 -188
  93. package/src/llm/providers/QwenProvider.ts +0 -199
  94. package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
  95. package/src/llm/utils.ts +0 -46
  96. package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
  97. package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
  98. package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
  99. package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
  100. package/src/providers/vectordb/MilvusProvider.ts +0 -134
  101. package/src/providers/vectordb/MongoDBProvider.ts +0 -250
  102. package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
  103. package/src/providers/vectordb/PineconeProvider.ts +0 -295
  104. package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
  105. package/src/providers/vectordb/QdrantProvider.ts +0 -294
  106. package/src/providers/vectordb/RedisProvider.ts +0 -105
  107. package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
  108. package/src/providers/vectordb/WeaviateProvider.ts +0 -172
  109. package/src/rag/DocumentChunker.ts +0 -144
  110. package/src/rag/EntityExtractor.ts +0 -90
  111. package/src/rag/LlamaIndexIngestor.ts +0 -60
  112. package/src/rag/Reranker.ts +0 -106
  113. package/src/rendering/IntentClassifier.ts +0 -167
  114. package/src/rendering/RendererRegistry.ts +0 -164
  115. package/src/rendering/RuleEngine.ts +0 -67
  116. package/src/rendering/VisualizationDecisionEngine.ts +0 -164
  117. package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
  118. package/src/rendering/index.ts +0 -12
  119. package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
  120. package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
  121. package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
  122. package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
  123. package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
  124. package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
  125. package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
  126. package/src/rendering/types.ts +0 -96
  127. package/src/server.ts +0 -156
  128. package/src/tailwind.css +0 -194
  129. package/src/telemetry/TelemetryService.ts +0 -330
  130. package/src/types/chat.ts +0 -89
  131. package/src/types/index.ts +0 -278
  132. package/src/types/pdf-parse.d.ts +0 -13
  133. package/src/types/props.ts +0 -169
  134. package/src/utils/DocumentParser.ts +0 -111
  135. package/src/utils/ProductExtractor.ts +0 -350
  136. package/src/utils/SchemaMapper.ts +0 -176
  137. package/src/utils/UITransformer.ts +0 -1812
  138. package/src/utils/synonyms.ts +0 -80
  139. package/src/utils/templateUtils.ts +0 -78
  140. package/src/version.ts +0 -6
@@ -1,220 +0,0 @@
1
- /**
2
- * ConfigFetcher.ts — Dynamically fetches project credentials from Retrivora Control Plane
3
- * without hardcoding plain-text master keys in NPM package binaries.
4
- *
5
- * SECURITY: The SDK must ONLY call the Retrivora Control Plane at https://www.retrivora.com.
6
- * It must never call the end user's own localhost or any other endpoint.
7
- * LLM and embedding calls are proxied through https://www.retrivora.com/api/v1 which
8
- * forwards to https://llm.retrivora.com with the server-side LITELLM_MASTER_KEY.
9
- */
10
-
11
- import { ProjectChatSettings, normalizeProjectSettings } from './ProjectSettings';
12
- import { SDK_VERSION } from '../version';
13
-
14
- export interface RemoteVectorConfig {
15
- apiKey: string;
16
- indexName: string;
17
- provider: string;
18
- projectId?: string;
19
- namespace?: string;
20
- }
21
-
22
- export interface RemoteEmbeddingConfig {
23
- provider: string;
24
- model: string;
25
- baseUrl: string;
26
- apiKey: string;
27
- profile?: string;
28
- }
29
-
30
- export interface RemoteLLMConfig {
31
- provider: string;
32
- model: string;
33
- baseUrl: string;
34
- apiKey: string;
35
- profile?: string;
36
- }
37
-
38
- export interface RemoteConfig {
39
- projectId?: string;
40
- tier?: string;
41
- isActive?: boolean;
42
- expiresAt?: string;
43
- vectorDb: RemoteVectorConfig;
44
- embedding: RemoteEmbeddingConfig;
45
- llm: RemoteLLMConfig;
46
- workspace?: {
47
- namespace: string;
48
- indexName: string;
49
- };
50
- projectSettings?: ProjectChatSettings;
51
- }
52
-
53
- // Legacy alias
54
- export type { RemoteVectorConfig as RemoteConfig_ };
55
-
56
- /**
57
- * The single source of truth for the Retrivora Control Plane URL.
58
- * The SDK must only communicate with this endpoint — never with the end user's localhost.
59
- */
60
- const CONTROL_PLANE_URL = 'https://www.retrivora.com';
61
-
62
- /**
63
- * The LLM/Embedding proxy gateway. All LLM and embedding requests are routed
64
- * through https://www.retrivora.com/api/v1, which validates the license key and
65
- * forwards to https://llm.retrivora.com with the server-side master key.
66
- * End users never need to know about llm.retrivora.com directly.
67
- */
68
- const LLM_PROXY_BASE_URL = 'https://www.retrivora.com/api/v1';
69
-
70
- export class ConfigFetcher {
71
- private static cache = new Map<string, { config: RemoteConfig; cachedAt: number }>();
72
- private static readonly TTL_MS = 5 * 60 * 1000; // 5-minute in-memory session cache
73
-
74
- /**
75
- * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
76
- *
77
- * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
78
- * The server validates the license against the database and returns:
79
- * - validity (tier, isActive, expiresAt)
80
- * - LLM model info
81
- * - embedding model info
82
- * - Pinecone index name and workspace/namespace
83
- *
84
- * The Pinecone API key is NOT returned (server-only). The SDK uses local
85
- * PINECONE_API_KEY if available, or vector operations are handled server-side.
86
- */
87
- static async fetchRemoteConfig(projectId: string, licenseKey?: string): Promise<RemoteConfig | null> {
88
- const cacheKey = `${projectId}:${licenseKey || ''}`;
89
- const now = Date.now();
90
- const cached = this.cache.get(cacheKey);
91
-
92
- if (cached && now - cached.cachedAt < this.TTL_MS) {
93
- return cached.config;
94
- }
95
-
96
- // SECURITY: Only call the Retrivora Control Plane — never localhost or any other endpoint.
97
- // Environment overrides are allowed for explicit server-side configuration, but
98
- // localhost URLs are explicitly excluded to prevent calling the end user's own app.
99
- const controlPlaneUrls = [
100
- process.env.RETRIVORA_CONTROL_PLANE_URL,
101
- process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
102
- CONTROL_PLANE_URL,
103
- ]
104
- .filter((url): url is string => {
105
- if (!url) return false;
106
- // Allow localhost only if explicitly configured via env vars, otherwise prevent it for security
107
- const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
108
- if (!isEnvVar && (url.includes('localhost') || url.includes('127.0.0.1'))) return false;
109
- return true;
110
- })
111
- .map((url) => url.replace(/\/$/, ''));
112
-
113
- for (const baseUrl of controlPlaneUrls) {
114
- try {
115
- const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
116
- //console.log(`[ConfigFetcher] Fetching config from: ${url}`);
117
- const res = await fetch(url, {
118
- method: 'GET',
119
- headers: {
120
- 'Content-Type': 'application/json',
121
- 'x-sdk-version': SDK_VERSION,
122
- ...(licenseKey ? { 'x-license-key': licenseKey } : {}),
123
- },
124
- });
125
-
126
- //console.log(`[ConfigFetcher] Response status: ${res.status}`);
127
- if (!res.ok) {
128
- console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
129
- }
130
-
131
- if (res.ok) {
132
- const data = await res.json();
133
- // NOTE: The config API intentionally does NOT return vectorDb.apiKey (server-only secret).
134
- // We check for data.success and data.vectorDb presence instead.
135
- if (data?.success && data?.vectorDb) {
136
- const fetchedProjectId = data.projectId || projectId;
137
- const config: RemoteConfig = {
138
- projectId: fetchedProjectId,
139
- tier: data.tier,
140
- isActive: data.isActive,
141
- expiresAt: data.expiresAt,
142
- vectorDb: {
143
- // Fetch apiKey from credentials API if available, else fallback to empty
144
- apiKey: data.vectorDb.apiKey || '',
145
- indexName: data.vectorDb.indexName || 'retrivora-free',
146
- provider: data.vectorDb.provider || 'pinecone',
147
- projectId: fetchedProjectId,
148
- namespace: data.workspace?.namespace || data.vectorDb.namespace || fetchedProjectId,
149
- },
150
- embedding: {
151
- provider: data.embedding?.provider || 'universal_rest',
152
- model: data.embedding?.model || 'text-embedding-004',
153
- // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
154
- baseUrl: data.embedding?.baseUrl || LLM_PROXY_BASE_URL,
155
- apiKey: data.embedding?.apiKey || licenseKey || '',
156
- profile: data.embedding?.profile || 'litellm',
157
- },
158
- llm: {
159
- provider: data.llm?.provider || 'universal_rest',
160
- model: data.llm?.model || 'llama-3.1-8b-instant',
161
- // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
162
- baseUrl: data.llm?.baseUrl || LLM_PROXY_BASE_URL,
163
- apiKey: data.llm?.apiKey || licenseKey || '',
164
- profile: data.llm?.profile || 'litellm',
165
- },
166
- workspace: data.workspace || {
167
- namespace: fetchedProjectId,
168
- indexName: data.vectorDb.indexName || 'retrivora-free',
169
- },
170
- projectSettings: normalizeProjectSettings(
171
- fetchedProjectId,
172
- data.projectSettings || data.settings
173
- ),
174
- };
175
- // Now fetch credentials if licenseKey is provided
176
- if (licenseKey) {
177
- try {
178
- const credUrl = `${baseUrl}/api/v1/credentials`;
179
- const credRes = await fetch(credUrl, {
180
- method: 'POST',
181
- headers: {
182
- 'Content-Type': 'application/json',
183
- },
184
- body: JSON.stringify({ licenseKey, projectId: fetchedProjectId }),
185
- });
186
- if (credRes.ok) {
187
- const credData = await credRes.json();
188
- if (credData?.success && credData?.credentials) {
189
- if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
190
- config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
191
- }
192
- if (credData.credentials.litellmApiKey) {
193
- config.llm.apiKey = credData.credentials.litellmApiKey;
194
- config.embedding.apiKey = credData.credentials.litellmApiKey;
195
- }
196
- }
197
- }
198
- } catch (e) {
199
- console.warn('[ConfigFetcher] Failed to fetch credentials:', e);
200
- }
201
- }
202
-
203
- this.cache.set(cacheKey, { config, cachedAt: now });
204
- return config;
205
- }
206
- }
207
- } catch {
208
- /* Try next fallback URL */
209
- }
210
- }
211
-
212
- return null;
213
- }
214
-
215
- /** Convenience: fetch only vector DB config (backwards compat). */
216
- static async fetchRemoteVectorConfig(projectId: string, licenseKey?: string): Promise<RemoteVectorConfig | null> {
217
- const config = await this.fetchRemoteConfig(projectId, licenseKey);
218
- return config?.vectorDb ?? null;
219
- }
220
- }
@@ -1,165 +0,0 @@
1
- /**
2
- * ConfigResolver — validates and normalizes host configuration.
3
- * It merges host-provided config with environment defaults.
4
- *
5
- * The `getRagConfig()` result is memoized at module level so that
6
- * environment variables are only parsed once per process, avoiding
7
- * repeated work in serverless cold starts and per-request handler calls.
8
- */
9
- import { RagConfig, UniversalRagConfig, RAGConfig, RetrievalConfig, WorkflowConfig } from '../config/RagConfig';
10
- import { mergeDefined } from '../utils/templateUtils';
11
- import { getEnvConfig } from '../config/serverConfig';
12
-
13
-
14
-
15
- export class ConfigResolver {
16
- /**
17
- * Resolves the final configuration by merging host-provided config with environment defaults.
18
- * @param hostConfig - Partial configuration passed from the host application.
19
- */
20
- static resolve(hostConfig?: Partial<RagConfig>, env: Record<string, string | undefined> = process.env): RagConfig {
21
- const envConfig = getEnvConfig(env);
22
-
23
- if (!hostConfig) {
24
- return envConfig;
25
- }
26
-
27
- // Deep merge: host config wins over env config at every level
28
- return {
29
- ...envConfig,
30
- ...hostConfig,
31
- projectId: hostConfig.projectId || envConfig.projectId,
32
- vectorDb: hostConfig.vectorDb
33
- ? {
34
- ...envConfig.vectorDb,
35
- ...hostConfig.vectorDb,
36
- options: {
37
- ...envConfig.vectorDb.options,
38
- ...(hostConfig.vectorDb.options || {}),
39
- },
40
- }
41
- : envConfig.vectorDb,
42
- llm: hostConfig.llm
43
- ? {
44
- ...envConfig.llm,
45
- ...hostConfig.llm,
46
- options: {
47
- ...(envConfig.llm.options || {}),
48
- ...(hostConfig.llm.options || {}),
49
- },
50
- }
51
- : envConfig.llm,
52
- embedding: hostConfig.embedding
53
- ? {
54
- ...envConfig.embedding,
55
- ...hostConfig.embedding,
56
- options: {
57
- ...(envConfig.embedding.options || {}),
58
- ...(hostConfig.embedding.options || {}),
59
- },
60
- }
61
- : envConfig.embedding,
62
- ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
63
- projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
64
- rag: hostConfig.rag ? { ...envConfig.rag, ...hostConfig.rag } : envConfig.rag,
65
- telemetry: hostConfig.telemetry
66
- ? {
67
- ...envConfig.telemetry,
68
- ...hostConfig.telemetry,
69
- }
70
- : envConfig.telemetry,
71
- };
72
- }
73
-
74
- /**
75
- * Resolves the public SDK config shape used by `new Retrivora({...})`.
76
- * Supports aliases from the product prompt while preserving existing env
77
- * fallback behavior.
78
- */
79
- static resolveUniversal(hostConfig?: UniversalRagConfig, env: Record<string, string | undefined> = process.env): RagConfig {
80
- if (!hostConfig) return this.resolve(undefined, env);
81
-
82
- const normalized: Partial<RagConfig> = {
83
- ...hostConfig,
84
- vectorDb: hostConfig.vectorDb ?? hostConfig.vectorDatabase,
85
- rag: this.mergeRetrievalWorkflow(hostConfig.rag, hostConfig.retrieval, hostConfig.workflow),
86
- } as Partial<RagConfig>;
87
-
88
- return this.resolve(normalized, env);
89
- }
90
-
91
- /**
92
- * Validates the configuration for required fields.
93
- */
94
- static validate(config: RagConfig): void {
95
- if (!config.projectId) {
96
- throw new Error('[ConfigResolver] projectId is required');
97
- }
98
- if (!config.vectorDb.provider) {
99
- throw new Error('[ConfigResolver] vectorDb.provider is required');
100
- }
101
- if (!config.llm.provider) {
102
- throw new Error('[ConfigResolver] llm.provider is required');
103
- }
104
- }
105
-
106
- private static mergeRetrievalWorkflow(
107
- rag?: RAGConfig,
108
- retrieval?: RetrievalConfig,
109
- workflow?: WorkflowConfig,
110
- ): RAGConfig | undefined {
111
- if (!rag && !retrieval && !workflow) return undefined;
112
-
113
- const normalized: RAGConfig = { ...(rag ?? {}) };
114
-
115
- if (retrieval) {
116
- normalized.topK = retrieval.topK ?? normalized.topK;
117
- normalized.scoreThreshold = retrieval.scoreThreshold ?? normalized.scoreThreshold;
118
- normalized.useReranking = retrieval.useReranking ?? normalized.useReranking;
119
-
120
- if (retrieval.strategy === 'hybrid') normalized.architecture = normalized.architecture ?? 'hybrid';
121
- if (retrieval.strategy === 'agentic') normalized.architecture = 'multi-agent';
122
- if (retrieval.strategy === 'contextual-compression') {
123
- normalized.useReranking = true;
124
- normalized.architecture = normalized.architecture ?? 'retrieve-and-rerank';
125
- }
126
- }
127
-
128
- if (workflow?.type) {
129
- const type = workflow.type;
130
- if (type === 'naive-rag') {
131
- normalized.architecture = 'naive';
132
- normalized.useReranking = false;
133
- normalized.useGraphRetrieval = false;
134
- } else if (type === 'retrieve-and-rerank') {
135
- normalized.architecture = 'retrieve-and-rerank';
136
- normalized.useReranking = true;
137
- } else if (type === 'multimodal-rag') {
138
- normalized.architecture = 'multimodal';
139
- } else if (type === 'graph-rag') {
140
- normalized.architecture = 'graph';
141
- normalized.useGraphRetrieval = true;
142
- } else if (type === 'hybrid-rag') {
143
- normalized.architecture = 'hybrid';
144
- } else if (type === 'agentic-router') {
145
- normalized.architecture = 'agentic-router';
146
- } else if (type === 'multi-agent-rag' || type === 'multi-agent' || type === 'agentic' || type === 'agentic-rag') {
147
- normalized.architecture = 'multi-agent';
148
- } else if (type === 'simple-rag' || type === 'rag') {
149
- normalized.architecture = normalized.architecture ?? 'naive';
150
- }
151
- }
152
-
153
- // Default fallbacks based on architecture configuration
154
- if (normalized.architecture === 'retrieve-and-rerank') {
155
- normalized.useReranking = true;
156
- } else if (normalized.architecture === 'graph') {
157
- normalized.useGraphRetrieval = true;
158
- } else if (normalized.architecture === 'naive') {
159
- normalized.useReranking = false;
160
- normalized.useGraphRetrieval = false;
161
- }
162
-
163
- return normalized;
164
- }
165
- }
@@ -1,197 +0,0 @@
1
- import { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig } from '../config/RagConfig';
2
- import {
3
- UI_BORDER_RADIUS_OPTIONS,
4
- } from '../config/constants';
5
- import { ProviderRegistry } from './ProviderRegistry';
6
- import { LLMFactory } from '../llm/LLMFactory';
7
- import { ConfigurationException } from '../exceptions';
8
-
9
- export interface ValidationError {
10
- field: string;
11
- message: string;
12
- suggestion?: string;
13
- severity: 'error' | 'warning';
14
- }
15
-
16
- /**
17
- * ConfigValidator.ts — Comprehensive configuration validation.
18
- * Uses a pluggable architecture to delegate provider-specific checks.
19
- */
20
- export class ConfigValidator {
21
- /**
22
- * Validates the entire RagConfig object.
23
- */
24
- static async validate(config: RagConfig): Promise<ValidationError[]> {
25
- const errors: ValidationError[] = [];
26
-
27
- if (!config.projectId) {
28
- errors.push({
29
- field: 'projectId',
30
- message: 'projectId is required',
31
- severity: 'error',
32
- });
33
- }
34
-
35
- errors.push(...(await this.validateVectorDbConfig(config.vectorDb)));
36
- errors.push(...(await this.validateLLMConfig(config.llm)));
37
-
38
- if (config.embedding) {
39
- errors.push(...(await this.validateEmbeddingConfig(config.embedding)));
40
- } else if (config.llm.provider === 'anthropic') {
41
- errors.push({
42
- field: 'embedding',
43
- message: 'Embedding config is required when using Anthropic LLM',
44
- suggestion: 'Provide embedding config with provider (e.g., "openai" or "ollama")',
45
- severity: 'error',
46
- });
47
- }
48
-
49
- if (config.ui) {
50
- errors.push(...this.validateUIConfig(config.ui as Record<string, unknown>));
51
- }
52
-
53
- if (config.rag) {
54
- errors.push(...this.validateRAGConfig(config.rag as Record<string, unknown>));
55
- }
56
-
57
- return errors;
58
- }
59
-
60
- private static async validateVectorDbConfig(config: VectorDBConfig): Promise<ValidationError[]> {
61
- const errors: ValidationError[] = [];
62
-
63
- if (!config.provider) {
64
- errors.push({ field: 'vectorDb.provider', message: 'Vector database provider is required', severity: 'error' });
65
- return errors;
66
- }
67
-
68
- if (!config.indexName) {
69
- errors.push({ field: 'vectorDb.indexName', message: 'Vector database index name is required', severity: 'error' });
70
- }
71
-
72
- // Delegate to pluggable validator if available
73
- const validator = await ProviderRegistry.getVectorValidator(config.provider);
74
- if (validator) {
75
- errors.push(...validator.validate(config as unknown as Record<string, unknown>));
76
- } else {
77
- // Fallback for non-migrated providers
78
- this.fallbackVectorValidation(config, errors);
79
- }
80
-
81
- return errors;
82
- }
83
-
84
- private static async validateLLMConfig(config: LLMConfig): Promise<ValidationError[]> {
85
- const errors: ValidationError[] = [];
86
-
87
- if (!config.provider) {
88
- errors.push({ field: 'llm.provider', message: 'LLM provider is required', severity: 'error' });
89
- return errors;
90
- }
91
-
92
- const validator = LLMFactory.getValidator(config.provider);
93
- if (validator) {
94
- errors.push(...validator.validate(config as unknown as Record<string, unknown>));
95
- } else {
96
- this.fallbackLLMValidation(config, errors);
97
- }
98
-
99
- if (config.temperature !== undefined && (config.temperature < 0 || config.temperature > 2)) {
100
- errors.push({ field: 'llm.temperature', message: 'Temperature must be between 0 and 2', severity: 'error' });
101
- }
102
-
103
- return errors;
104
- }
105
-
106
- private static async validateEmbeddingConfig(config: EmbeddingConfig): Promise<ValidationError[]> {
107
- const errors: ValidationError[] = [];
108
-
109
- if (!config.provider) {
110
- errors.push({ field: 'embedding.provider', message: 'Embedding provider is required', severity: 'error' });
111
- return errors;
112
- }
113
-
114
- const validator = LLMFactory.getValidator(config.provider as unknown as LLMConfig['provider']);
115
- if (validator) {
116
- errors.push(...validator.validate(config as unknown as Record<string, unknown>));
117
- } else {
118
- this.fallbackEmbeddingValidation(config, errors);
119
- }
120
-
121
- return errors;
122
- }
123
-
124
- /**
125
- * Temporary fallbacks for providers not yet migrated to the pluggable architecture.
126
- */
127
- private static fallbackVectorValidation(config: VectorDBConfig, errors: ValidationError[]) {
128
- const opts = (config.options || {}) as Record<string, unknown>;
129
- switch (config.provider) {
130
- case 'milvus':
131
- if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
132
- errors.push({ field: 'vectorDb.options.baseUrl', message: 'Milvus connection info required', severity: 'error' });
133
- }
134
- break;
135
- case 'qdrant':
136
- if (!opts.baseUrl && !opts.url) {
137
- errors.push({ field: 'vectorDb.options.baseUrl', message: 'Qdrant URL required', severity: 'error' });
138
- }
139
- break;
140
- // ... other fallbacks
141
- }
142
- }
143
-
144
- private static fallbackLLMValidation(config: LLMConfig, errors: ValidationError[]) {
145
- if (!config.model) {
146
- errors.push({ field: 'llm.model', message: 'LLM model name is required', severity: 'error' });
147
- }
148
- // Add other LLM fallbacks if needed
149
- }
150
-
151
- private static fallbackEmbeddingValidation(config: EmbeddingConfig, errors: ValidationError[]) {
152
- if (!config.model) {
153
- errors.push({ field: 'embedding.model', message: 'Embedding model name is required', severity: 'error' });
154
- }
155
- }
156
-
157
- private static validateUIConfig(config: Record<string, unknown>): ValidationError[] {
158
- const errors: ValidationError[] = [];
159
-
160
- if (config.primaryColor && !this.isValidCSSColor(config.primaryColor as string)) {
161
- errors.push({ field: 'ui.primaryColor', message: 'Invalid CSS color format', severity: 'warning' });
162
- }
163
-
164
- if (config.borderRadius && !UI_BORDER_RADIUS_OPTIONS.includes(config.borderRadius as typeof UI_BORDER_RADIUS_OPTIONS[number])) {
165
- errors.push({ field: 'ui.borderRadius', message: `borderRadius must be one of: ${UI_BORDER_RADIUS_OPTIONS.join(', ')}`, severity: 'warning' });
166
- }
167
-
168
- return errors;
169
- }
170
-
171
- private static validateRAGConfig(config: Record<string, unknown>): ValidationError[] {
172
- const errors: ValidationError[] = [];
173
- if (config.topK !== undefined && (typeof config.topK !== 'number' || config.topK <= 0)) {
174
- errors.push({ field: 'rag.topK', message: 'topK must be a positive integer', severity: 'error' });
175
- }
176
- return errors;
177
- }
178
-
179
- private static isValidCSSColor(color: string): boolean {
180
- const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
181
- const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
182
- const namedColors = ['red', 'blue', 'green', 'black', 'white', 'transparent'];
183
- return hexRegex.test(color) || rgbRegex.test(color) || namedColors.includes(color.toLowerCase());
184
- }
185
-
186
- static async validateAndThrow(config: RagConfig): Promise<void> {
187
- const errors = await this.validate(config);
188
- const errorItems = errors.filter((e) => e.severity === 'error');
189
-
190
- if (errorItems.length > 0) {
191
- const message = errorItems
192
- .map((e) => `${e.field}: ${e.message}${e.suggestion ? ` (${e.suggestion})` : ''}`)
193
- .join('\n ');
194
- throw new ConfigurationException(`[ConfigValidator] Configuration validation failed:\n ${message}`, errorItems);
195
- }
196
- }
197
- }