@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,82 +0,0 @@
1
- /**
2
- * Pre-configured templates for popular AI and Vector services.
3
- * Use these as defaults in the Universal Adapters.
4
- */
5
-
6
- const OPENAI_BASE = {
7
- chatPath: '/chat/completions',
8
- embedPath: '/embeddings',
9
- responseExtractPath: 'choices[0].message.content',
10
- embedExtractPath: 'data[0].embedding',
11
- chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"max_tokens":{{maxTokens}},"temperature":{{temperature}}}',
12
- };
13
-
14
- export const LLM_PROFILES = {
15
- 'openai-compatible': OPENAI_BASE,
16
- 'litellm': {
17
- ...OPENAI_BASE,
18
- },
19
- 'anthropic-claude': {
20
- chatPath: '/v1/messages',
21
- responseExtractPath: 'content[0].text',
22
- headers: { 'anthropic-version': '2023-06-01' },
23
- chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"max_tokens":{{maxTokens}}}',
24
- },
25
- 'google-gemini': {
26
- chatPath: '/v1beta/models/{{model}}:generateContent',
27
- responseExtractPath: 'candidates[0].content.parts[0].text',
28
- chatPayloadTemplate: '{"contents":[{"parts":[{"text":"{{messages}}"}]}]}',
29
- },
30
- 'github-copilot': {
31
- ...OPENAI_BASE,
32
- chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"temperature":{{temperature}}}',
33
- },
34
- 'ollama-standard': {
35
- chatPath: '/api/chat',
36
- embedPath: '/api/embeddings',
37
- responseExtractPath: 'message.content',
38
- embedExtractPath: 'embedding',
39
- chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"stream":false}',
40
- embedPayloadTemplate: '{"model":"{{model}}","prompt":"{{input}}"}',
41
- },
42
- };
43
-
44
- export const VECTOR_PROFILES = {
45
- 'pinecone-rest': {
46
- queryPath: '/query',
47
- upsertPath: '/vectors/upsert',
48
- responseExtractPath: 'matches',
49
- idPath: 'id',
50
- scorePath: 'score',
51
- contentPath: 'metadata.content',
52
- metadataPath: 'metadata',
53
- queryPayloadTemplate: '{"vector":{{vector}},"topK":{{topK}},"includeMetadata":true,"namespace":"{{namespace}}"}',
54
- },
55
- 'mongodb-atlas': {
56
- queryPath: '/action/aggregate',
57
- responseExtractPath: 'documents',
58
- idPath: '_id',
59
- scorePath: 'score',
60
- contentPath: 'content',
61
- metadataPath: 'metadata',
62
- queryPayloadTemplate: '{"collection":"{{index}}","database":"ai_db","dataSource":"Cluster0","pipeline":[{"$vectorSearch":{"index":"vector_index","path":"embedding","queryVector":{{vector}},"numCandidates":100,"limit":{{topK}}}},{"$project":{"_id":1,"content":1,"metadata":1,"score":{"$meta":"vectorSearchScore"}}}]}',
63
- },
64
- 'chromadb': {
65
- queryPath: '/api/v1/collections/{{index}}/query',
66
- upsertPath: '/api/v1/collections/{{index}}/add',
67
- responseExtractPath: 'matches',
68
- idPath: 'id',
69
- scorePath: 'distance',
70
- contentPath: 'document',
71
- metadataPath: 'metadata',
72
- },
73
- 'qdrant': {
74
- queryPath: '/collections/{{index}}/points/search',
75
- upsertPath: '/collections/{{index}}/points',
76
- responseExtractPath: 'result',
77
- idPath: 'id',
78
- scorePath: 'score',
79
- contentPath: 'payload.content',
80
- metadataPath: 'payload',
81
- },
82
- };
@@ -1,64 +0,0 @@
1
- /**
2
- * constants.ts — Centralized definitions of acceptable configuration values.
3
- *
4
- * This file serves as the single source of truth for all statically supported
5
- * providers and stylistic options in the Retrivora AI RAG Engine.
6
- */
7
- export const VERSION = '1.9.6';
8
-
9
- export const VECTOR_DB_PROVIDERS = [
10
- 'pinecone',
11
- 'pgvector',
12
- 'postgresql',
13
- 'mongodb',
14
- 'qdrant',
15
- 'milvus',
16
- 'chromadb',
17
- 'redis',
18
- 'weaviate',
19
- 'rest',
20
- 'universal_rest',
21
- 'custom',
22
- ] as const;
23
-
24
- export const LLM_PROVIDERS = [
25
- 'openai',
26
- 'anthropic',
27
- 'ollama',
28
- 'gemini',
29
- 'groq',
30
- 'qwen',
31
- 'rest',
32
- 'universal_rest',
33
- 'custom',
34
- ] as const;
35
-
36
- export const EMBEDDING_PROVIDERS = [
37
- 'openai',
38
- 'ollama',
39
- 'gemini',
40
- 'qwen',
41
- 'rest',
42
- 'universal_rest',
43
- 'custom',
44
- ] as const;
45
-
46
- export const GRAPH_DB_PROVIDERS = [
47
- 'neo4j',
48
- 'memgraph',
49
- 'simple',
50
- 'custom',
51
- ] as const;
52
-
53
- export const PROVIDERS_WITH_EMBEDDINGS = [
54
- 'openai',
55
- 'ollama',
56
- 'gemini',
57
- 'qwen',
58
- 'rest',
59
- 'universal_rest',
60
- ] as const;
61
-
62
- export const UI_VISUAL_STYLES = ['glass', 'solid'] as const;
63
-
64
- export const UI_BORDER_RADIUS_OPTIONS = ['none', 'sm', 'md', 'lg', 'xl', 'full'] as const;
@@ -1,378 +0,0 @@
1
- /**
2
- * serverConfig.ts — reads RagConfig from environment variables at runtime.
3
- *
4
- * This keeps secrets server-side and never exposes them to the browser.
5
- * Consumer projects set these env vars in their .env.local file.
6
- *
7
- * Supported VECTOR_DB_PROVIDER values and their required env vars:
8
- * pinecone → PINECONE_API_KEY, PINECONE_INDEX
9
- * pgvector /
10
- * postgresql → PGVECTOR_CONNECTION_STRING, VECTOR_DB_INDEX
11
- * mongodb → MONGODB_URI, MONGODB_DB, MONGODB_COLLECTION
12
- * qdrant → QDRANT_URL, QDRANT_API_KEY
13
- * milvus → MILVUS_URL (e.g. http://localhost:19530)
14
- * chromadb → CHROMADB_URL (e.g. http://localhost:8000)
15
- * weaviate → WEAVIATE_URL, WEAVIATE_API_KEY
16
- * redis → REDIS_URL, REDIS_API_KEY
17
- * rest /
18
- * universal_rest→ VECTOR_BASE_URL, VECTOR_DB_REST_API_KEY
19
- */
20
-
21
- import { RagConfig, LLMProvider, EmbeddingProvider } from './RagConfig';
22
- import { LicenseVerifier } from '../core/LicenseVerifier';
23
- import {
24
- VECTOR_DB_PROVIDERS,
25
- LLM_PROVIDERS,
26
- EMBEDDING_PROVIDERS,
27
- } from './constants';
28
-
29
- /**
30
- * Runtime tier configuration injected from the /api/v1/config + /api/v1/credentials
31
- * API responses at app startup. This overrides static env-var defaults so that
32
- * the tier-based model selection from the license is applied to all SDK calls.
33
- */
34
- export interface RuntimeTierConfig {
35
- llmModel?: string;
36
- embeddingModel?: string;
37
- /** Custom system prompt from project configuration */
38
- systemPrompt?: string;
39
- /** LiteLLM master key for authenticating with llm.retrivora.com */
40
- litellmApiKey?: string;
41
- /** LiteLLM gateway base URL (defaults to https://llm.retrivora.com/api/v1) */
42
- llmBaseUrl?: string;
43
- embeddingBaseUrl?: string;
44
- maxTokens?: number;
45
- topK?: number;
46
- chunkSize?: number;
47
- chunkOverlap?: number;
48
- tier?: string;
49
- }
50
-
51
- /** Module-level store for runtime-injected tier config */
52
- let _runtimeConfig: RuntimeTierConfig | null = null;
53
-
54
- /**
55
- * Inject tier-based config fetched from /api/v1/config + /api/v1/credentials.
56
- * Call this once after successful license init (e.g. in validate-env.ts).
57
- */
58
- export function injectRuntimeConfig(config: RuntimeTierConfig): void {
59
- _runtimeConfig = config;
60
- // console.log('[serverConfig] ✅ Runtime tier config injected:', {
61
- // tier: config.tier,
62
- // llmModel: config.llmModel,
63
- // embeddingModel: config.embeddingModel,
64
- // llmBaseUrl: config.llmBaseUrl,
65
- // hasLitellmKey: !!config.litellmApiKey,
66
- // });
67
- }
68
-
69
- /** Returns the currently injected runtime config, or null if not yet set. */
70
- export function getRuntimeConfig(): RuntimeTierConfig | null {
71
- return _runtimeConfig;
72
- }
73
-
74
- function readString(env: Record<string, string | undefined>, name: string): string | undefined {
75
- const value = env[name]?.trim();
76
- return value ? value : undefined;
77
- }
78
-
79
- function readNumber(env: Record<string, string | undefined>, name: string, fallback: number): number {
80
- const value = env[name];
81
- if (!value) return fallback;
82
- const parsed = Number(value);
83
- if (!Number.isFinite(parsed)) {
84
- throw new Error(`[getRagConfig] ${name} must be a valid number`);
85
- }
86
- return parsed;
87
- }
88
-
89
- function readEnum<T extends readonly string[]>(
90
- env: Record<string, string | undefined>,
91
- name: string,
92
- fallback: T[number],
93
- allowed: T
94
- ): T[number] {
95
- const value = readString(env, name) ?? fallback;
96
- if ((allowed as readonly string[]).includes(value)) {
97
- return value as T[number];
98
- }
99
- throw new Error(`[getRagConfig] ${name} must be one of: ${allowed.join(', ')}`);
100
- }
101
-
102
- export function getRagConfig(baseConfig?: Partial<RagConfig>, env: Record<string, string | undefined> = process.env): RagConfig {
103
- return getEnvConfig(env, baseConfig);
104
- }
105
-
106
- export function getEnvConfig(env: Record<string, string | undefined> = process.env, base?: Partial<RagConfig>): RagConfig {
107
- const licenseKey =
108
- readString(env, 'RAG_LICENSE_KEY') ??
109
- readString(env, 'RETRIVORA_LICENSE_KEY') ??
110
- readString(env, 'NEXT_PUBLIC_RETRIVORA_LICENSE_KEY') ??
111
- readString(env, 'LICENSE_KEY') ??
112
- base?.licenseKey;
113
-
114
- const jwtProjectId = (() => {
115
- if (!licenseKey) return undefined;
116
- try {
117
- const parts = licenseKey.split('.');
118
- if (parts.length >= 2) {
119
- const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
120
- return payload?.projectId;
121
- }
122
- } catch { /* ignore */ }
123
- return undefined;
124
- })();
125
-
126
- const projectId =
127
- readString(env, 'RAG_PROJECT_ID') ??
128
- readString(env, 'NEXT_PUBLIC_RAG_PROJECT_ID') ??
129
- readString(env, 'NEXT_PUBLIC_PROJECT_ID') ??
130
- base?.projectId ??
131
- jwtProjectId ??
132
- 'default';
133
-
134
- const telemetryEnabled =
135
- readString(env, 'TELEMETRY_ENABLED') === 'true' ||
136
- readString(env, 'NEXT_PUBLIC_TELEMETRY_ENABLED') === 'true' ||
137
- base?.telemetry?.enabled ||
138
- Boolean(licenseKey);
139
-
140
- const vectorProvider = readEnum(env, 'VECTOR_DB_PROVIDER', 'pinecone', VECTOR_DB_PROVIDERS);
141
- const embeddingDimensions = readNumber(env, 'EMBEDDING_DIMENSIONS', 768);
142
-
143
- // Build provider-specific vectorDb options
144
- const vectorDbOptions: Record<string, unknown> = {};
145
-
146
- if (vectorProvider === 'pinecone') {
147
- vectorDbOptions.apiKey = readString(env, 'PINECONE_API_KEY') ?? (base?.vectorDb?.options?.apiKey as string) ?? process.env.PINECONE_API_KEY ?? '';
148
- vectorDbOptions.indexName = readString(env, 'PINECONE_INDEX') ?? (base?.vectorDb?.indexName as string) ?? (base?.vectorDb?.options?.indexName as string) ?? process.env.PINECONE_INDEX ?? 'retrivora-free';
149
- } else if (vectorProvider === 'pgvector' || vectorProvider === 'postgresql') {
150
- vectorDbOptions.connectionString = readString(env, 'PGVECTOR_CONNECTION_STRING') ?? readString(env, 'POSTGRES_URL') ?? (base?.vectorDb?.options?.connectionString as string) ?? '';
151
- vectorDbOptions.tables = (readString(env, 'VECTOR_DB_TABLES') ?? readString(env, 'POSTGRES_TABLES'))?.split(',').map(t => t.trim()) ?? (base?.vectorDb?.options?.tables as string[]);
152
- vectorDbOptions.searchFields = readString(env, 'POSTGRES_SEARCH_FIELDS')?.split(',').map(f => f.trim()) ?? (base?.vectorDb?.options?.searchFields as string[]);
153
- vectorDbOptions.dimensions = embeddingDimensions;
154
- } else if (vectorProvider === 'mongodb') {
155
- vectorDbOptions.uri = readString(env, 'MONGODB_URI') ?? (base?.vectorDb?.options?.uri as string) ?? '';
156
- vectorDbOptions.database = readString(env, 'MONGODB_DB') ?? (base?.vectorDb?.options?.database as string) ?? '';
157
- vectorDbOptions.collection = readString(env, 'MONGODB_COLLECTION') ?? (base?.vectorDb?.options?.collection as string) ?? '';
158
- vectorDbOptions.indexName = readString(env, 'MONGODB_INDEX_NAME') ?? (base?.vectorDb?.indexName as string) ?? (base?.vectorDb?.options?.indexName as string) ?? 'vector_index';
159
- } else if (vectorProvider === 'qdrant') {
160
- vectorDbOptions.baseUrl = readString(env, 'QDRANT_URL') ?? (base?.vectorDb?.options?.baseUrl as string) ?? 'http://localhost:6333';
161
- vectorDbOptions.apiKey = readString(env, 'QDRANT_API_KEY') ?? (base?.vectorDb?.options?.apiKey as string);
162
- vectorDbOptions.dimensions = embeddingDimensions;
163
- } else if (vectorProvider === 'milvus') {
164
- vectorDbOptions.baseUrl = readString(env, 'MILVUS_URL') ?? 'http://localhost:19530';
165
- vectorDbOptions.apiKey = readString(env, 'MILVUS_API_KEY');
166
- } else if (vectorProvider === 'chromadb') {
167
- vectorDbOptions.baseUrl = readString(env, 'CHROMADB_URL') ?? 'http://localhost:8000';
168
- } else if (vectorProvider === 'weaviate') {
169
- vectorDbOptions.baseUrl = readString(env, 'WEAVIATE_URL') ?? 'http://localhost:8080';
170
- vectorDbOptions.apiKey = readString(env, 'WEAVIATE_API_KEY');
171
- } else if (vectorProvider === 'redis') {
172
- vectorDbOptions.baseUrl = readString(env, 'REDIS_URL') ?? '';
173
- vectorDbOptions.apiKey = readString(env, 'REDIS_API_KEY');
174
- } else if (vectorProvider === 'rest') {
175
- vectorDbOptions.baseUrl = readString(env, 'VECTOR_DB_REST_URL') ?? '';
176
- vectorDbOptions.headers = readString(env, 'VECTOR_DB_REST_API_KEY')
177
- ? { 'api-key': readString(env, 'VECTOR_DB_REST_API_KEY') }
178
- : {};
179
- } else if (vectorProvider === 'universal_rest') {
180
- vectorDbOptions.baseUrl =
181
- readString(env, 'VECTOR_BASE_URL') ?? readString(env, 'VECTOR_DB_REST_URL') ?? '';
182
- vectorDbOptions.profile = readString(env, 'VECTOR_UNIVERSAL_PROFILE');
183
- vectorDbOptions.headers = readString(env, 'VECTOR_DB_REST_API_KEY')
184
- ? { Authorization: `Bearer ${readString(env, 'VECTOR_DB_REST_API_KEY')}` }
185
- : {};
186
- }
187
-
188
- const llmApiKeyByProvider: Record<string, string | undefined> = {
189
- openai: readString(env, 'OPENAI_API_KEY'),
190
- anthropic: readString(env, 'ANTHROPIC_API_KEY'),
191
- gemini: readString(env, 'GEMINI_API_KEY'),
192
- ollama: undefined,
193
- universal_rest: readString(env, 'LLM_API_KEY'),
194
- rest: readString(env, 'LLM_API_KEY'),
195
- custom: readString(env, 'LLM_API_KEY'),
196
- };
197
-
198
- const embeddingApiKeyByProvider: Record<string, string | undefined> = {
199
- openai: readString(env, 'OPENAI_API_KEY'),
200
- anthropic: readString(env, 'ANTHROPIC_API_KEY'), // Anthropic needs a separate embedding provider; key kept for completeness
201
- gemini: readString(env, 'GEMINI_API_KEY'),
202
- ollama: undefined,
203
- universal_rest: readString(env, 'EMBEDDING_API_KEY') ?? readString(env, 'OPENAI_API_KEY'),
204
- custom: readString(env, 'EMBEDDING_API_KEY') ?? readString(env, 'OPENAI_API_KEY'),
205
- };
206
-
207
- /**
208
- * Provider-aware default models.
209
- * Applied when LLM_MODEL env var is not explicitly set.
210
- */
211
- const DEFAULT_MODEL_BY_PROVIDER: Record<string, string> = {
212
- openai: 'gpt-4o',
213
- anthropic: 'claude-3-5-sonnet-20241022',
214
- gemini: 'gemini-2.0-flash',
215
- ollama: 'llama3',
216
- universal_rest: 'default',
217
- rest: 'default',
218
- custom: 'default',
219
- };
220
-
221
- // Check if the license key belongs to a Free / Trial tier
222
- const isFreeTier = (() => {
223
- if (!licenseKey) return true;
224
- try {
225
- const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
226
- return tier === 'free_trial' || tier === 'free_tier' || tier === 'free' || tier === 'hobby';
227
- } catch {
228
- return true;
229
- }
230
- })();
231
-
232
- // Tier-based model selection (resolved from license tier)
233
- const tierBasedLLMModel = isFreeTier ? 'llama-3.1-8b-instant' : 'llama-3.3-70b-versatile';
234
- const tierBasedEmbeddingModel = isFreeTier ? 'text-embedding-004' : 'text-embedding-004';
235
-
236
- // Default gateway: always use LiteLLM at llm.retrivora.com for end-users
237
- // End-users provide license key + project ID; the gateway validates and routes internally
238
- const controlPlaneUrl = readString(env, 'RETRIVORA_CONTROL_PLANE_URL') ?? readString(env, 'NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL');
239
- const defaultGatewayUrl = controlPlaneUrl
240
- ? `${controlPlaneUrl.replace(/\/$/, '')}/api/v1`
241
- : 'https://llm.retrivora.com/api/v1';
242
-
243
- // ── Runtime-injected tier config (from /api/v1/config + /api/v1/credentials) ──
244
- // Priority: explicit env var > injected runtime config > static tier fallback
245
- const rt = _runtimeConfig;
246
-
247
- const defaultLlmProvider = 'universal_rest';
248
- const llmProvider = (readEnum(env, 'LLM_PROVIDER', defaultLlmProvider, LLM_PROVIDERS) ?? base?.llm?.provider ?? defaultLlmProvider) as LLMProvider;
249
- // llmBaseUrl: env var wins, then injected gateway URL, then static default
250
- const llmBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.llm?.baseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
251
- // llmModel: env var wins, then injected tier model, then static tier fallback
252
- const llmModel = readString(env, 'LLM_MODEL') ?? base?.llm?.model ?? rt?.llmModel ?? tierBasedLLMModel;
253
- // llmApiKey: LITELLM_MASTER_KEY env wins, then injected litellm key, then licenseKey
254
- const llmApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.llm?.apiKey ?? licenseKey;
255
- const llmProfile = readString(env, 'LLM_UNIVERSAL_PROFILE') ?? (base?.llm?.options?.profile as string) ?? 'litellm';
256
-
257
- // console.log('[serverConfig] 🔧 LLM Configuration:', {
258
- // baseUrl: llmBaseUrl,
259
- // model: llmModel,
260
- // provider: llmProvider,
261
- // hasApiKey: !!llmApiKey,
262
- // source: rt?.llmModel ? 'runtime-injected' : 'env/fallback',
263
- // });
264
-
265
- const defaultEmbeddingProvider = 'universal_rest';
266
- const embeddingProvider = (readEnum(env, 'EMBEDDING_PROVIDER', defaultEmbeddingProvider, EMBEDDING_PROVIDERS) ?? base?.embedding?.provider ?? defaultEmbeddingProvider) as EmbeddingProvider;
267
- const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? rt?.embeddingBaseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
268
- const embeddingModel = readString(env, 'EMBEDDING_MODEL') ?? base?.embedding?.model ?? rt?.embeddingModel ?? tierBasedEmbeddingModel;
269
- // embeddingApiKey: same key as LLM (LiteLLM gateway handles both)
270
- const embeddingApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.embedding?.apiKey ?? licenseKey;
271
- const embeddingProfile = readString(env, 'EMBEDDING_UNIVERSAL_PROFILE') ?? (base?.embedding?.options?.profile as string) ?? 'litellm';
272
-
273
- // console.log('[serverConfig] 🔧 Embedding Configuration:', {
274
- // baseUrl: embeddingBaseUrl,
275
- // model: embeddingModel,
276
- // provider: embeddingProvider,
277
- // hasApiKey: !!embeddingApiKey,
278
- // source: rt?.embeddingModel ? 'runtime-injected' : 'env/fallback',
279
- // });
280
-
281
- return {
282
- projectId,
283
- licenseKey,
284
- vectorDb: {
285
- provider: vectorProvider,
286
- indexName:
287
- readString(env, 'VECTOR_DB_INDEX') ??
288
- (vectorDbOptions.indexName as string) ??
289
- 'rag-index',
290
- options: vectorDbOptions,
291
- },
292
- llm: {
293
- provider: llmProvider,
294
- model: llmModel,
295
- apiKey: llmApiKey,
296
- baseUrl: llmBaseUrl,
297
- systemPrompt: readString(env, 'LLM_SYSTEM_PROMPT') ?? rt?.systemPrompt,
298
- maxTokens: readNumber(env, 'LLM_MAX_TOKENS', rt?.maxTokens ?? 4096),
299
- temperature: readNumber(env, 'LLM_TEMPERATURE', 0.7),
300
- options: {
301
- profile: llmProfile,
302
- thinking: readString(env, 'LLM_THINKING') === 'true' || readString(env, 'LLM_THINKING') === 'enabled' ? true : (readString(env, 'LLM_THINKING') === 'false' ? false : undefined),
303
- thinkingBudget: env.LLM_THINKING_BUDGET ? parseInt(env.LLM_THINKING_BUDGET, 10) : undefined,
304
- },
305
- },
306
- embedding: {
307
- provider: embeddingProvider,
308
- model: embeddingModel,
309
- apiKey: embeddingApiKey,
310
- baseUrl: embeddingBaseUrl,
311
- dimensions: embeddingDimensions,
312
- queryPrefix: readString(env, 'EMBEDDING_QUERY_PREFIX'),
313
- documentPrefix: readString(env, 'EMBEDDING_DOCUMENT_PREFIX'),
314
- options: {
315
- profile: embeddingProfile,
316
- },
317
- },
318
- ui: {
319
- title: readString(env, 'NEXT_PUBLIC_UI_TITLE') ?? readString(env, 'UI_TITLE') ?? 'AI Assistant',
320
- subtitle: readString(env, 'NEXT_PUBLIC_UI_SUBTITLE') ?? readString(env, 'UI_SUBTITLE') ?? 'Powered by RAG',
321
- primaryColor: readString(env, 'NEXT_PUBLIC_PRIMARY_COLOR') ?? readString(env, 'UI_PRIMARY_COLOR') ?? '#10b981',
322
- accentColor: readString(env, 'NEXT_PUBLIC_ACCENT_COLOR') ?? readString(env, 'UI_ACCENT_COLOR') ?? '#3b82f6',
323
- logoUrl: readString(env, 'NEXT_PUBLIC_LOGO_URL') ?? readString(env, 'UI_LOGO_URL'),
324
- placeholder: readString(env, 'NEXT_PUBLIC_PLACEHOLDER') ?? readString(env, 'UI_PLACEHOLDER') ?? 'Ask me anything…',
325
- showSources: (readString(env, 'NEXT_PUBLIC_SHOW_SOURCES') ?? readString(env, 'UI_SHOW_SOURCES') ?? 'true') !== 'false',
326
- welcomeMessage:
327
- readString(env, 'NEXT_PUBLIC_WELCOME_MESSAGE') ??
328
- readString(env, 'UI_WELCOME_MESSAGE') ??
329
- "Hello! I'm your AI assistant. Ask me anything about your documents.",
330
- visualStyle: (readString(env, 'NEXT_PUBLIC_UI_VISUAL_STYLE') ?? readString(env, 'UI_VISUAL_STYLE') ?? 'glass') as 'glass' | 'solid',
331
- borderRadius: (readString(env, 'NEXT_PUBLIC_UI_BORDER_RADIUS') ?? readString(env, 'UI_BORDER_RADIUS') ?? 'xl') as 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full',
332
- allowUpload: (readString(env, 'NEXT_PUBLIC_ALLOW_UPLOAD') ?? readString(env, 'UI_ALLOW_UPLOAD') ?? 'false') === 'true',
333
- },
334
- rag: {
335
- topK: readNumber(env, 'RAG_TOP_K', rt?.topK ?? 5),
336
- scoreThreshold: readNumber(env, 'RAG_SCORE_THRESHOLD', 0),
337
- chunkSize: readNumber(env, 'RAG_CHUNK_SIZE', rt?.chunkSize ?? 1000),
338
- chunkOverlap: readNumber(env, 'RAG_CHUNK_OVERLAP', rt?.chunkOverlap ?? 200),
339
- filterableFields: readString(env, 'RAG_FILTERABLE_FIELDS')?.split(',').map(f => f.trim()),
340
- // Query pipeline toggles — read from .env.local
341
- useQueryTransformation: readString(env, 'RAG_USE_QUERY_TRANSFORMATION') === 'true',
342
- useReranking: readString(env, 'RAG_USE_RERANKING') === 'true',
343
- useGraphRetrieval: readString(env, 'RAG_USE_GRAPH_RETRIEVAL') === 'true',
344
- architecture: (readString(env, 'RAG_ARCHITECTURE') ?? 'simple') as 'simple' | 'graph' | 'hybrid' | 'agentic',
345
- chunkingStrategy: (readString(env, 'RAG_CHUNKING_STRATEGY') ?? 'recursive') as 'recursive' | 'markdown' | 'semantic' | 'llamaindex',
346
- uiMapping: (() => {
347
- const raw = readString(env, 'RAG_UI_MAPPING');
348
- if (!raw) return undefined;
349
- try { return JSON.parse(raw) as Record<string, string>; } catch { return undefined; }
350
- })(),
351
- },
352
- telemetry: {
353
- enabled: telemetryEnabled,
354
- url: readString(env, 'TELEMETRY_URL') ?? readString(env, 'NEXT_PUBLIC_TELEMETRY_URL') ?? base?.telemetry?.url ?? 'https://www.retrivora.com/api/telemetry',
355
- },
356
- // Optional graph DB — driven by GRAPH_DB_PROVIDER env var
357
- ...(readString(env, 'GRAPH_DB_PROVIDER') ? {
358
- graphDb: {
359
- provider: readString(env, 'GRAPH_DB_PROVIDER')! as 'neo4j' | 'memgraph' | 'simple' | 'custom',
360
- options: {
361
- uri: readString(env, 'GRAPH_DB_URI'),
362
- username: readString(env, 'GRAPH_DB_USERNAME'),
363
- password: readString(env, 'GRAPH_DB_PASSWORD'),
364
- },
365
- },
366
- } : {}),
367
- mcpServers: (() => {
368
- const raw = readString(env, 'MCP_SERVERS') ?? readString(env, 'NEXT_PUBLIC_MCP_SERVERS');
369
- if (!raw) return undefined;
370
- try {
371
- return JSON.parse(raw);
372
- } catch (e) {
373
- console.warn('[serverConfig] Failed to parse MCP_SERVERS env:', e);
374
- return undefined;
375
- }
376
- })(),
377
- };
378
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * uiConstants.ts — UI-specific constants for the package's React components.
3
- *
4
- * Kept inside the package src so they resolve correctly when the package
5
- * is consumed via npm without Next.js path-alias configuration.
6
- */
7
-
8
- import { ClientConfig } from '../types';
9
-
10
- export const DEFAULT_CONFIG: ClientConfig = {
11
- projectId: 'default',
12
- ui: {
13
- title: 'AI Assistant',
14
- subtitle: 'Powered by RAG',
15
- primaryColor: '#6366f1',
16
- accentColor: '#8b5cf6',
17
- logoUrl: '',
18
- placeholder: 'Ask me anything…',
19
- showSources: true,
20
- welcomeMessage: "Hello! I'm your AI assistant. Ask me anything about your documents.",
21
- showWidget: true,
22
- poweredBy: 'RAG',
23
- visualStyle: 'glass',
24
- borderRadius: 'xl',
25
- allowUpload: true,
26
- allowResize: true,
27
- enableVoiceInput: true,
28
- theme: 'light'
29
- },
30
- };
31
-
32
- /** Maps the `borderRadius` config value to a Tailwind class. */
33
- export const BORDER_RADIUS_MAP: Record<string, string> = {
34
- none: 'rounded-none',
35
- sm: 'rounded-sm',
36
- md: 'rounded-md',
37
- lg: 'rounded-lg',
38
- xl: 'rounded-xl',
39
- full: 'rounded-3xl',
40
- };
41
-
42
- /** Default suggested prompts shown on the chat welcome screen. */
43
- export const CHAT_SUGGESTIONS: string[] = [
44
- 'What can you help me with?',
45
- 'Summarise the key topics',
46
- 'Show me an example',
47
- ];