@retrivora-ai/rag-engine 2.4.3 → 2.4.6

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 (142) hide show
  1. package/README.md +22 -0
  2. package/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-BGslIR5l.d.mts} +65 -4
  3. package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-C3gY6kZ0.d.ts} +65 -4
  4. package/dist/handlers/index.js +668 -837
  5. package/dist/handlers/index.mjs +678 -837
  6. package/dist/index.css +5 -0
  7. package/dist/index.d.mts +4 -28
  8. package/dist/index.d.ts +4 -28
  9. package/dist/index.js +91 -43
  10. package/dist/index.min.css +1 -1
  11. package/dist/index.mjs +91 -43
  12. package/dist/server.d.mts +21 -7
  13. package/dist/server.d.ts +21 -7
  14. package/dist/server.js +731 -875
  15. package/dist/server.mjs +741 -875
  16. package/package.json +11 -4
  17. package/src/LicensedRetrivora.ts +0 -278
  18. package/src/app/api/chat/route.ts +0 -4
  19. package/src/app/api/health/route.ts +0 -5
  20. package/src/app/api/ingest/route.ts +0 -27
  21. package/src/app/api/suggestions/route.ts +0 -5
  22. package/src/app/api/upload/route.ts +0 -5
  23. package/src/app/constants.tsx +0 -270
  24. package/src/app/favicon.ico +0 -0
  25. package/src/app/globals.css +0 -449
  26. package/src/app/layout.tsx +0 -22
  27. package/src/app/page.tsx +0 -64
  28. package/src/app/types.ts +0 -30
  29. package/src/browser.tsx +0 -127
  30. package/src/components/ChatWidget.tsx +0 -393
  31. package/src/components/ChatWindow.tsx +0 -952
  32. package/src/components/CodeViewer.tsx +0 -56
  33. package/src/components/ConfigProvider.tsx +0 -141
  34. package/src/components/DocumentUpload.tsx +0 -354
  35. package/src/components/DynamicChart.tsx +0 -297
  36. package/src/components/HourglassLoader.tsx +0 -87
  37. package/src/components/MarkdownComponents.tsx +0 -186
  38. package/src/components/MessageBubble.tsx +0 -498
  39. package/src/components/ObservabilityPanel.tsx +0 -374
  40. package/src/components/ProductCard.tsx +0 -107
  41. package/src/components/ProductCarousel.tsx +0 -97
  42. package/src/components/SourceCard.tsx +0 -61
  43. package/src/components/ThemeProvider.tsx +0 -8
  44. package/src/components/ThemeToggle.tsx +0 -29
  45. package/src/components/ThinkingBlock.tsx +0 -75
  46. package/src/components/UIDispatcher.tsx +0 -342
  47. package/src/components/VisualizationRenderer.tsx +0 -621
  48. package/src/components/constants.tsx +0 -503
  49. package/src/config/ConfigBuilder.ts +0 -285
  50. package/src/config/EmbeddingStrategy.ts +0 -148
  51. package/src/config/LicenseConfigResolver.ts +0 -298
  52. package/src/config/RagConfig.ts +0 -328
  53. package/src/config/UniversalProfiles.ts +0 -82
  54. package/src/config/constants.ts +0 -64
  55. package/src/config/serverConfig.ts +0 -378
  56. package/src/config/uiConstants.ts +0 -47
  57. package/src/core/BatchProcessor.ts +0 -385
  58. package/src/core/CircuitBreaker.ts +0 -118
  59. package/src/core/ConfigFetcher.ts +0 -220
  60. package/src/core/ConfigResolver.ts +0 -165
  61. package/src/core/ConfigValidator.ts +0 -197
  62. package/src/core/DatabaseStorage.ts +0 -526
  63. package/src/core/FreeTierLimitsGuard.ts +0 -281
  64. package/src/core/LLMRouter.ts +0 -79
  65. package/src/core/LangChainAgent.ts +0 -132
  66. package/src/core/LicenseValidator.ts +0 -284
  67. package/src/core/LicenseVerifier.ts +0 -261
  68. package/src/core/MultiAgentCoordinator.ts +0 -239
  69. package/src/core/Pipeline.ts +0 -1279
  70. package/src/core/PluginManager.ts +0 -277
  71. package/src/core/ProjectSettings.ts +0 -247
  72. package/src/core/ProviderHealthCheck.ts +0 -133
  73. package/src/core/ProviderInterfaces.ts +0 -37
  74. package/src/core/ProviderRegistry.ts +0 -156
  75. package/src/core/QueryProcessor.ts +0 -399
  76. package/src/core/Retrivora.ts +0 -98
  77. package/src/core/VectorPlugin.ts +0 -193
  78. package/src/core/mcp.ts +0 -261
  79. package/src/exceptions/index.ts +0 -131
  80. package/src/handlers/index.ts +0 -1625
  81. package/src/hooks/useHydrated.ts +0 -13
  82. package/src/hooks/useProjectSettings.ts +0 -105
  83. package/src/hooks/useRagChat.ts +0 -436
  84. package/src/hooks/useStoredMessages.ts +0 -64
  85. package/src/index.css +0 -4269
  86. package/src/index.ts +0 -137
  87. package/src/lib/plugin.ts +0 -24
  88. package/src/llm/ILLMProvider.ts +0 -60
  89. package/src/llm/LLMFactory.ts +0 -141
  90. package/src/llm/providers/AnthropicProvider.ts +0 -215
  91. package/src/llm/providers/GeminiProvider.ts +0 -311
  92. package/src/llm/providers/GroqProvider.ts +0 -184
  93. package/src/llm/providers/OllamaProvider.ts +0 -232
  94. package/src/llm/providers/OpenAIProvider.ts +0 -188
  95. package/src/llm/providers/QwenProvider.ts +0 -199
  96. package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
  97. package/src/llm/utils.ts +0 -46
  98. package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
  99. package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
  100. package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
  101. package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
  102. package/src/providers/vectordb/MilvusProvider.ts +0 -134
  103. package/src/providers/vectordb/MongoDBProvider.ts +0 -250
  104. package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
  105. package/src/providers/vectordb/PineconeProvider.ts +0 -295
  106. package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
  107. package/src/providers/vectordb/QdrantProvider.ts +0 -294
  108. package/src/providers/vectordb/RedisProvider.ts +0 -105
  109. package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
  110. package/src/providers/vectordb/WeaviateProvider.ts +0 -172
  111. package/src/rag/DocumentChunker.ts +0 -144
  112. package/src/rag/EntityExtractor.ts +0 -90
  113. package/src/rag/LlamaIndexIngestor.ts +0 -60
  114. package/src/rag/Reranker.ts +0 -106
  115. package/src/rendering/IntentClassifier.ts +0 -167
  116. package/src/rendering/RendererRegistry.ts +0 -164
  117. package/src/rendering/RuleEngine.ts +0 -67
  118. package/src/rendering/VisualizationDecisionEngine.ts +0 -164
  119. package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
  120. package/src/rendering/index.ts +0 -12
  121. package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
  122. package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
  123. package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
  124. package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
  125. package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
  126. package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
  127. package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
  128. package/src/rendering/types.ts +0 -96
  129. package/src/server.ts +0 -156
  130. package/src/tailwind.css +0 -194
  131. package/src/telemetry/TelemetryService.ts +0 -330
  132. package/src/types/chat.ts +0 -89
  133. package/src/types/index.ts +0 -278
  134. package/src/types/pdf-parse.d.ts +0 -13
  135. package/src/types/props.ts +0 -169
  136. package/src/utils/DocumentParser.ts +0 -111
  137. package/src/utils/ProductExtractor.ts +0 -350
  138. package/src/utils/SchemaMapper.ts +0 -176
  139. package/src/utils/UITransformer.ts +0 -1812
  140. package/src/utils/synonyms.ts +0 -80
  141. package/src/utils/templateUtils.ts +0 -78
  142. package/src/version.ts +0 -6
@@ -1,277 +0,0 @@
1
- /**
2
- * PluginManager — Universal plugin registration and lifecycle management
3
- *
4
- * Provides a flexible architecture for registering custom vector DBs, LLMs,
5
- * and other providers without modifying core code.
6
- *
7
- * Features:
8
- * - Dynamic plugin registration
9
- * - Dependency resolution
10
- * - Plugin validation
11
- * - Lifecycle management
12
- */
13
-
14
- export interface PluginMetadata {
15
- /** Unique identifier (e.g., 'myprovider.vectordb.custom') */
16
- id: string;
17
- /** Human-readable name */
18
- name: string;
19
- /** Plugin version */
20
- version: string;
21
- /** Detailed description */
22
- description?: string;
23
- /** Author information */
24
- author?: string;
25
- /** Supported capabilities */
26
- capabilities: PluginCapability[];
27
- /** Required dependencies (other plugin IDs) */
28
- dependencies?: string[];
29
- }
30
-
31
- export type PluginCapability = 'chat' | 'embed' | 'vector-db' | 'reranker' | 'parser';
32
-
33
- export interface IPluginProvider {
34
- /**
35
- * Get plugin metadata
36
- */
37
- getMetadata(): PluginMetadata;
38
-
39
- /**
40
- * Validate configuration for this plugin
41
- */
42
- validateConfig?(config: Record<string, unknown>): {
43
- valid: boolean;
44
- errors?: string[];
45
- };
46
-
47
- /**
48
- * Initialize plugin with configuration
49
- */
50
- initialize(config: Record<string, unknown>): Promise<void>;
51
-
52
- /**
53
- * Check if plugin is ready
54
- */
55
- isReady(): Promise<boolean>;
56
-
57
- /**
58
- * Gracefully shutdown plugin
59
- */
60
- shutdown(): Promise<void>;
61
-
62
- /**
63
- * Get plugin-specific health status
64
- */
65
- getHealthStatus?(): Promise<{
66
- healthy: boolean;
67
- details?: Record<string, unknown>;
68
- }>;
69
- }
70
-
71
- export interface PluginDescriptor {
72
- metadata: PluginMetadata;
73
- factory: (config: Record<string, unknown>) => Promise<IPluginProvider>;
74
- validateConfig?: (config: Record<string, unknown>) => {
75
- valid: boolean;
76
- errors?: string[];
77
- };
78
- }
79
-
80
- export class PluginManager {
81
- private static readonly registeredPlugins: Map<string, PluginDescriptor> = new Map();
82
- private static readonly instances: Map<string, IPluginProvider> = new Map();
83
-
84
- /**
85
- * Register a new plugin provider
86
- */
87
- static registerPlugin(descriptor: PluginDescriptor): void {
88
- const { metadata } = descriptor;
89
-
90
- if (this.registeredPlugins.has(metadata.id)) {
91
- throw new Error(
92
- `[PluginManager] Plugin with ID "${metadata.id}" is already registered. ` +
93
- `Use unregisterPlugin() first if you need to replace it.`
94
- );
95
- }
96
-
97
- // Validate metadata
98
- if (!metadata.id || !metadata.name || !metadata.version) {
99
- throw new Error(
100
- '[PluginManager] Plugin metadata must include id, name, and version'
101
- );
102
- }
103
-
104
- if (metadata.capabilities.length === 0) {
105
- throw new Error('[PluginManager] Plugin must declare at least one capability');
106
- }
107
-
108
- this.registeredPlugins.set(metadata.id, descriptor);
109
- // console.log(
110
- // `[PluginManager] Registered plugin: ${metadata.name} v${metadata.version} (${metadata.id})`
111
- // );
112
- }
113
-
114
- /**
115
- * Unregister a plugin and cleanup its instance
116
- */
117
- static async unregisterPlugin(pluginId: string): Promise<void> {
118
- if (this.instances.has(pluginId)) {
119
- const instance = this.instances.get(pluginId)!;
120
- await instance.shutdown();
121
- this.instances.delete(pluginId);
122
- }
123
-
124
- this.registeredPlugins.delete(pluginId);
125
- }
126
-
127
- /**
128
- * Get plugin metadata
129
- */
130
- static getPluginMetadata(pluginId: string): PluginMetadata | null {
131
- return this.registeredPlugins.get(pluginId)?.metadata ?? null;
132
- }
133
-
134
- /**
135
- * List all registered plugins with optional filtering by capability
136
- */
137
- static listPlugins(capability?: PluginCapability): PluginMetadata[] {
138
- const plugins = Array.from(this.registeredPlugins.values()).map(d => d.metadata);
139
-
140
- if (capability) {
141
- return plugins.filter(p => p.capabilities.includes(capability));
142
- }
143
-
144
- return plugins;
145
- }
146
-
147
- /**
148
- * Create and cache a plugin instance with dependency resolution
149
- */
150
- static async createInstance(
151
- pluginId: string,
152
- config: Record<string, unknown>
153
- ): Promise<IPluginProvider> {
154
- // Return cached instance if already created
155
- if (this.instances.has(pluginId)) {
156
- return this.instances.get(pluginId)!;
157
- }
158
-
159
- const descriptor = this.registeredPlugins.get(pluginId);
160
- if (!descriptor) {
161
- throw new Error(
162
- `[PluginManager] Plugin "${pluginId}" not registered. ` +
163
- `Registered plugins: ${Array.from(this.registeredPlugins.keys()).join(', ')}`
164
- );
165
- }
166
-
167
- const { metadata, factory } = descriptor;
168
-
169
- // Validate configuration
170
- if (descriptor.validateConfig) {
171
- const validation = descriptor.validateConfig(config);
172
- if (!validation.valid) {
173
- throw new Error(
174
- `[PluginManager] Invalid configuration for plugin "${pluginId}": ` +
175
- `${validation.errors?.join('; ') || 'Unknown error'}`
176
- );
177
- }
178
- }
179
-
180
- // Resolve dependencies
181
- if (metadata.dependencies && metadata.dependencies.length > 0) {
182
- for (const depId of metadata.dependencies) {
183
- if (!this.instances.has(depId)) {
184
- throw new Error(
185
- `[PluginManager] Plugin "${pluginId}" requires "${depId}" to be initialized first`
186
- );
187
- }
188
- }
189
- }
190
-
191
- // Initialize plugin
192
- //console.log(`[PluginManager] Initializing plugin: ${pluginId}`);
193
- const instance = await factory(config);
194
-
195
- // Verify plugin is ready
196
- const isReady = await instance.isReady();
197
- if (!isReady) {
198
- throw new Error(
199
- `[PluginManager] Plugin "${pluginId}" failed to initialize properly`
200
- );
201
- }
202
-
203
- // Cache instance
204
- this.instances.set(pluginId, instance);
205
-
206
- return instance;
207
- }
208
-
209
- /**
210
- * Get cached instance of a plugin
211
- */
212
- static getInstance(pluginId: string): IPluginProvider | null {
213
- return this.instances.get(pluginId) ?? null;
214
- }
215
-
216
- /**
217
- * Check if a plugin is ready (either registered or instantiated)
218
- */
219
- static isPluginAvailable(pluginId: string): boolean {
220
- return this.registeredPlugins.has(pluginId) || this.instances.has(pluginId);
221
- }
222
-
223
- /**
224
- * Shutdown all plugin instances
225
- */
226
- static async shutdownAll(): Promise<void> {
227
- const errors: Error[] = [];
228
-
229
- for (const [pluginId, instance] of this.instances.entries()) {
230
- try {
231
- await instance.shutdown();
232
- //console.log(`[PluginManager] Shutdown plugin: ${pluginId}`);
233
- } catch (error) {
234
- errors.push(
235
- new Error(`Failed to shutdown plugin ${pluginId}: ${error instanceof Error ? error.message : String(error)}`)
236
- );
237
- }
238
- }
239
-
240
- this.instances.clear();
241
-
242
- if (errors.length > 0) {
243
- throw new AggregateError(errors, '[PluginManager] Errors during shutdown');
244
- }
245
- }
246
-
247
- /**
248
- * Get health status of all instantiated plugins
249
- */
250
- static async getHealthStatus(): Promise<
251
- Map<string, { healthy: boolean; details?: Record<string, unknown> }>
252
- > {
253
- const status = new Map();
254
-
255
- for (const [pluginId, instance] of this.instances.entries()) {
256
- try {
257
- const health = await instance.getHealthStatus?.();
258
- status.set(pluginId, health ?? { healthy: true });
259
- } catch (error) {
260
- status.set(pluginId, {
261
- healthy: false,
262
- details: { error: error instanceof Error ? error.message : String(error) },
263
- });
264
- }
265
- }
266
-
267
- return status;
268
- }
269
-
270
- /**
271
- * Clear all registered and instantiated plugins (for testing)
272
- */
273
- static reset(): void {
274
- this.registeredPlugins.clear();
275
- this.instances.clear();
276
- }
277
- }
@@ -1,247 +0,0 @@
1
- import type { UIConfig } from '../config/RagConfig';
2
-
3
- export type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
4
- export type ThemeMode = 'light' | 'dark' | 'system';
5
- export type AuthMode = 'public' | 'anonymous' | 'jwt' | 'oauth' | 'okta' | 'auth0' | 'supabase' | 'firebase' | 'sso' | 'custom_token';
6
-
7
- export interface ProjectBrandingSettings {
8
- companyName: string;
9
- botName: string;
10
- welcomeMessage: string;
11
- primaryColor: string;
12
- secondaryColor: string;
13
- fontFamily: string;
14
- borderRadius: number;
15
- logoUrl: string;
16
- avatarUrl: string;
17
- customCss: string;
18
- }
19
-
20
- export interface ProjectAiSettings {
21
- defaultModel: string;
22
- embeddingModel: string;
23
- systemPrompt: string;
24
- memoryEnabled: boolean;
25
- multiModelEnabled: boolean;
26
- citationsEnabled: boolean;
27
- fileUploadEnabled: boolean;
28
- }
29
-
30
- export interface ProjectAuthSettings {
31
- mode: AuthMode;
32
- allowedOrigins: string[];
33
- requireVerifiedEmail: boolean;
34
- sessionTtlMinutes: number;
35
- }
36
-
37
- export interface ProjectWidgetSettings {
38
- position: WidgetPosition;
39
- theme: ThemeMode;
40
- lazyLoad: boolean;
41
- autoReconnect: boolean;
42
- persistConversations: boolean;
43
- showRetrivoraBranding: boolean;
44
- }
45
-
46
- export interface ProjectTelemetrySettings {
47
- enabled: boolean;
48
- collectBrowser: boolean;
49
- collectCountry: boolean;
50
- redactPii: boolean;
51
- retentionDays: number;
52
- }
53
-
54
- export interface ProjectChatSettings {
55
- projectId: string;
56
- branding: ProjectBrandingSettings;
57
- ai: ProjectAiSettings;
58
- auth: ProjectAuthSettings;
59
- widget: ProjectWidgetSettings;
60
- telemetry: ProjectTelemetrySettings;
61
- lifecycleHooks: string[];
62
- conversationFeatures: string[];
63
- updatedAt?: string;
64
- }
65
-
66
- export const DEFAULT_LIFECYCLE_HOOKS = [
67
- 'beforeInitialize',
68
- 'afterInitialize',
69
- 'beforeSend',
70
- 'afterResponse',
71
- 'onMessage',
72
- 'onCitationClick',
73
- 'onFeedback',
74
- 'onError',
75
- 'onReconnect',
76
- 'onFileUpload',
77
- ];
78
-
79
- export const DEFAULT_CONVERSATION_FEATURES = [
80
- 'History',
81
- 'Resume',
82
- 'Search',
83
- 'Export',
84
- 'Rename',
85
- 'Delete',
86
- 'Tags',
87
- 'Pinned',
88
- 'Unread',
89
- 'Ratings',
90
- ];
91
-
92
- export function createDefaultProjectSettings(projectId: string): ProjectChatSettings {
93
- return {
94
- projectId,
95
- branding: {
96
- companyName: 'Retrivora AI',
97
- botName: 'Retrivora Assistant',
98
- welcomeMessage: 'Hi, I can help you search your knowledge base.',
99
- primaryColor: '#6366f1',
100
- secondaryColor: '#8b5cf6',
101
- fontFamily: 'Inter',
102
- borderRadius: 14,
103
- logoUrl: '',
104
- avatarUrl: '',
105
- customCss: '',
106
- },
107
- ai: {
108
- defaultModel: 'llama-3.1-8b-instant',
109
- embeddingModel: 'text-embedding-3-small',
110
- systemPrompt: 'Answer using the connected knowledge base. Cite sources when available.',
111
- memoryEnabled: true,
112
- multiModelEnabled: true,
113
- citationsEnabled: true,
114
- fileUploadEnabled: true,
115
- },
116
- auth: {
117
- mode: 'public',
118
- allowedOrigins: [],
119
- requireVerifiedEmail: false,
120
- sessionTtlMinutes: 1440,
121
- },
122
- widget: {
123
- position: 'bottom-right',
124
- theme: 'light',
125
- lazyLoad: true,
126
- autoReconnect: true,
127
- persistConversations: true,
128
- showRetrivoraBranding: false,
129
- },
130
- telemetry: {
131
- enabled: true,
132
- collectBrowser: true,
133
- collectCountry: false,
134
- redactPii: true,
135
- retentionDays: 30,
136
- },
137
- lifecycleHooks: DEFAULT_LIFECYCLE_HOOKS,
138
- conversationFeatures: DEFAULT_CONVERSATION_FEATURES,
139
- };
140
- }
141
-
142
- function cleanString(value: unknown, fallback: string, maxLength = 2000) {
143
- if (typeof value !== 'string') return fallback;
144
- return value.trim().slice(0, maxLength);
145
- }
146
-
147
- function cleanBoolean(value: unknown, fallback: boolean) {
148
- return typeof value === 'boolean' ? value : fallback;
149
- }
150
-
151
- function cleanNumber(value: unknown, fallback: number, min: number, max: number) {
152
- const num = typeof value === 'number' ? value : Number(value);
153
- if (!Number.isFinite(num)) return fallback;
154
- return Math.min(Math.max(Math.round(num), min), max);
155
- }
156
-
157
- function cleanEnum<T extends string>(value: unknown, fallback: T, allowed: readonly T[]) {
158
- return typeof value === 'string' && allowed.includes(value as T) ? value as T : fallback;
159
- }
160
-
161
- function cleanStringList(value: unknown, fallback: string[], maxItems = 20) {
162
- if (!Array.isArray(value)) return fallback;
163
- const cleaned = value
164
- .filter((item): item is string => typeof item === 'string')
165
- .map((item) => item.trim())
166
- .filter(Boolean)
167
- .slice(0, maxItems);
168
- return cleaned.length > 0 ? Array.from(new Set(cleaned)) : fallback;
169
- }
170
-
171
- export function normalizeProjectSettings(projectId: string, input: Partial<ProjectChatSettings> | null | undefined): ProjectChatSettings {
172
- const defaults = createDefaultProjectSettings(projectId);
173
- const branding: Partial<ProjectBrandingSettings> = input?.branding || {};
174
- const ai: Partial<ProjectAiSettings> = input?.ai || {};
175
- const auth: Partial<ProjectAuthSettings> = input?.auth || {};
176
- const widget: Partial<ProjectWidgetSettings> = input?.widget || {};
177
- const telemetry: Partial<ProjectTelemetrySettings> = input?.telemetry || {};
178
-
179
- return {
180
- projectId,
181
- branding: {
182
- companyName: cleanString(branding.companyName, defaults.branding.companyName, 120),
183
- botName: cleanString(branding.botName, defaults.branding.botName, 120),
184
- welcomeMessage: cleanString(branding.welcomeMessage, defaults.branding.welcomeMessage, 500),
185
- primaryColor: cleanString(branding.primaryColor, defaults.branding.primaryColor, 32),
186
- secondaryColor: cleanString(branding.secondaryColor, defaults.branding.secondaryColor, 32),
187
- fontFamily: cleanString(branding.fontFamily, defaults.branding.fontFamily, 80),
188
- borderRadius: cleanNumber(branding.borderRadius, defaults.branding.borderRadius, 0, 32),
189
- logoUrl: cleanString(branding.logoUrl, defaults.branding.logoUrl, 500),
190
- avatarUrl: cleanString(branding.avatarUrl, defaults.branding.avatarUrl, 500),
191
- customCss: cleanString(branding.customCss, defaults.branding.customCss, 5000),
192
- },
193
- ai: {
194
- defaultModel: cleanString(ai.defaultModel, defaults.ai.defaultModel, 120),
195
- embeddingModel: cleanString(ai.embeddingModel, defaults.ai.embeddingModel, 120),
196
- systemPrompt: cleanString(ai.systemPrompt, defaults.ai.systemPrompt, 5000),
197
- memoryEnabled: cleanBoolean(ai.memoryEnabled, defaults.ai.memoryEnabled),
198
- multiModelEnabled: cleanBoolean(ai.multiModelEnabled, defaults.ai.multiModelEnabled),
199
- citationsEnabled: cleanBoolean(ai.citationsEnabled, defaults.ai.citationsEnabled),
200
- fileUploadEnabled: cleanBoolean(ai.fileUploadEnabled, defaults.ai.fileUploadEnabled),
201
- },
202
- auth: {
203
- mode: cleanEnum<AuthMode>(auth.mode, defaults.auth.mode, ['public', 'anonymous', 'jwt', 'oauth', 'okta', 'auth0', 'supabase', 'firebase', 'sso', 'custom_token']),
204
- allowedOrigins: cleanStringList(auth.allowedOrigins, defaults.auth.allowedOrigins, 25),
205
- requireVerifiedEmail: cleanBoolean(auth.requireVerifiedEmail, defaults.auth.requireVerifiedEmail),
206
- sessionTtlMinutes: cleanNumber(auth.sessionTtlMinutes, defaults.auth.sessionTtlMinutes, 15, 43200),
207
- },
208
- widget: {
209
- position: cleanEnum<WidgetPosition>(widget.position, defaults.widget.position, ['bottom-right', 'bottom-left', 'top-right', 'top-left']),
210
- theme: cleanEnum<ThemeMode>(widget.theme, defaults.widget.theme, ['light', 'dark', 'system']),
211
- lazyLoad: cleanBoolean(widget.lazyLoad, defaults.widget.lazyLoad),
212
- autoReconnect: cleanBoolean(widget.autoReconnect, defaults.widget.autoReconnect),
213
- persistConversations: cleanBoolean(widget.persistConversations, defaults.widget.persistConversations),
214
- showRetrivoraBranding: cleanBoolean(widget.showRetrivoraBranding, defaults.widget.showRetrivoraBranding),
215
- },
216
- telemetry: {
217
- enabled: cleanBoolean(telemetry.enabled, defaults.telemetry.enabled),
218
- collectBrowser: cleanBoolean(telemetry.collectBrowser, defaults.telemetry.collectBrowser),
219
- collectCountry: cleanBoolean(telemetry.collectCountry, defaults.telemetry.collectCountry),
220
- redactPii: cleanBoolean(telemetry.redactPii, defaults.telemetry.redactPii),
221
- retentionDays: cleanNumber(telemetry.retentionDays, defaults.telemetry.retentionDays, 1, 365),
222
- },
223
- lifecycleHooks: cleanStringList(input?.lifecycleHooks, defaults.lifecycleHooks, 30),
224
- conversationFeatures: cleanStringList(input?.conversationFeatures, defaults.conversationFeatures, 30),
225
- updatedAt: input?.updatedAt,
226
- };
227
- }
228
-
229
- export function projectSettingsToUiConfig(settings: ProjectChatSettings): Partial<UIConfig> {
230
- return {
231
- title: settings.branding.botName,
232
- subtitle: settings.branding.companyName,
233
- primaryColor: settings.branding.primaryColor,
234
- accentColor: settings.branding.secondaryColor,
235
- logoUrl: settings.branding.logoUrl || settings.branding.avatarUrl,
236
- welcomeMessage: settings.branding.welcomeMessage,
237
- poweredBy: settings.widget.showRetrivoraBranding ? 'Retrivora AI' : '',
238
- allowUpload: settings.ai.fileUploadEnabled,
239
- borderRadius: settings.branding.borderRadius <= 4
240
- ? 'sm'
241
- : settings.branding.borderRadius <= 8
242
- ? 'md'
243
- : settings.branding.borderRadius <= 16
244
- ? 'xl'
245
- : 'full',
246
- };
247
- }
@@ -1,133 +0,0 @@
1
- import { VectorDBConfig, LLMConfig, EmbeddingConfig } from '../config/RagConfig';
2
- import { ConfigValidator } from './ConfigValidator';
3
- import { ProviderRegistry } from './ProviderRegistry';
4
- import { LLMFactory } from '../llm/LLMFactory';
5
- import type { HealthCheckResult } from './ProviderInterfaces';
6
- export type { HealthCheckResult };
7
-
8
- /**
9
- * ProviderHealthCheck.ts — Pre-flight validation for vector DB and LLM providers.
10
- * Performs connectivity tests, credential validation, and capability checks.
11
- */
12
- export class ProviderHealthCheck {
13
- /**
14
- * Validates vector database configuration before initialization.
15
- */
16
- static async checkVectorProvider(config: VectorDBConfig): Promise<HealthCheckResult> {
17
- const timestamp = Date.now();
18
-
19
- const configErrors = await ConfigValidator.validate({
20
- projectId: 'health-check',
21
- vectorDb: config,
22
- llm: { provider: 'openai', model: 'gpt-4o', apiKey: 'none' },
23
- embedding: { provider: 'openai', model: 'text-embedding-3-small', apiKey: 'none' },
24
- });
25
-
26
- const vectorDbErrors = configErrors.filter((e) => e.field.startsWith('vectorDb'));
27
- if (vectorDbErrors.length > 0) {
28
- return {
29
- healthy: false,
30
- provider: config.provider,
31
- error: `Configuration validation failed: ${vectorDbErrors.map((e) => e.message).join('; ')}`,
32
- timestamp,
33
- };
34
- }
35
-
36
- try {
37
- const checker = await ProviderRegistry.getVectorHealthChecker(config.provider);
38
- if (checker) {
39
- return await checker.check(config as unknown as Record<string, unknown>);
40
- }
41
-
42
- // Fallback for non-migrated providers
43
- return await this.fallbackVectorHealthCheck(config, timestamp);
44
- } catch (error) {
45
- return {
46
- healthy: false,
47
- provider: config.provider,
48
- error: error instanceof Error ? error.message : String(error),
49
- timestamp,
50
- };
51
- }
52
- }
53
-
54
- private static async fallbackVectorHealthCheck(config: VectorDBConfig, timestamp: number): Promise<HealthCheckResult> {
55
- const opts = (config.options || {}) as Record<string, unknown>;
56
- const baseUrl = (opts.baseUrl as string) || (opts.uri as string);
57
-
58
- if (baseUrl && baseUrl.startsWith('http')) {
59
- try {
60
- const response = await fetch(`${baseUrl.replace(/\/$/, '')}/health`);
61
- return {
62
- healthy: response.ok,
63
- provider: config.provider,
64
- error: response.ok ? undefined : `Health check failed: ${response.status}`,
65
- timestamp,
66
- };
67
- } catch {
68
- return { healthy: false, provider: config.provider, error: 'Provider unreachable', timestamp };
69
- }
70
- }
71
-
72
- return {
73
- healthy: true,
74
- provider: config.provider,
75
- error: 'Pluggable health check not implemented; basic reachability assumed.',
76
- timestamp,
77
- };
78
- }
79
-
80
- /**
81
- * Validates LLM provider configuration.
82
- */
83
- static async checkLLMProvider(config: LLMConfig): Promise<HealthCheckResult> {
84
- const timestamp = Date.now();
85
- try {
86
- const checker = LLMFactory.getHealthChecker(config.provider);
87
- if (checker) {
88
- return await checker.check(config as unknown as Record<string, unknown>);
89
- }
90
-
91
- return {
92
- healthy: true,
93
- provider: config.provider,
94
- error: 'Pluggable health check not implemented; basic reachability assumed.',
95
- timestamp,
96
- };
97
- } catch (error) {
98
- return {
99
- healthy: false,
100
- provider: config.provider,
101
- error: error instanceof Error ? error.message : String(error),
102
- timestamp,
103
- };
104
- }
105
- }
106
-
107
- /**
108
- * Runs comprehensive health checks on all configured providers in parallel.
109
- */
110
- static async checkAll(
111
- vectorDbConfig: VectorDBConfig,
112
- llmConfig: LLMConfig,
113
- embeddingConfig?: EmbeddingConfig
114
- ): Promise<{
115
- vectorDb: HealthCheckResult;
116
- llm: HealthCheckResult;
117
- embedding?: HealthCheckResult;
118
- allHealthy: boolean;
119
- }> {
120
- const [vectorDb, llm, embedding] = await Promise.all([
121
- this.checkVectorProvider(vectorDbConfig),
122
- this.checkLLMProvider(llmConfig),
123
- embeddingConfig ? this.checkLLMProvider(embeddingConfig as LLMConfig) : Promise.resolve(undefined),
124
- ]);
125
-
126
- return {
127
- vectorDb,
128
- llm,
129
- embedding,
130
- allHealthy: vectorDb.healthy && llm.healthy && (!embedding || embedding.healthy),
131
- };
132
- }
133
- }
@@ -1,37 +0,0 @@
1
- import { ValidationError } from './ConfigValidator';
2
-
3
- /**
4
- * Interface for provider-specific configuration validation logic.
5
- */
6
- export interface IProviderValidator {
7
- /**
8
- * Validates the configuration for a specific provider.
9
- * @param config - The configuration object to validate.
10
- * @returns An array of validation errors (empty if valid).
11
- */
12
- validate(config: Record<string, unknown>): ValidationError[];
13
- }
14
-
15
- /**
16
- * Result of a provider health check.
17
- */
18
- export interface HealthCheckResult {
19
- healthy: boolean;
20
- provider: string;
21
- version?: string;
22
- capabilities?: Record<string, unknown>;
23
- error?: string;
24
- timestamp: number;
25
- }
26
-
27
- /**
28
- * Interface for provider-specific health checking logic.
29
- */
30
- export interface IProviderHealthChecker {
31
- /**
32
- * Performs a health check for a specific provider.
33
- * @param config - The configuration object used to connect to the provider.
34
- * @returns A promise that resolves to the health check result.
35
- */
36
- check(config: Record<string, unknown>): Promise<HealthCheckResult>;
37
- }