@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,239 +0,0 @@
1
- import { ILLMProvider } from '../llm/ILLMProvider';
2
- import { MCPRegistry } from './mcp';
3
- import { ChatMessage, ChatResponse } from '../types';
4
-
5
- interface CoordinatorOptions {
6
- llmProvider: ILLMProvider;
7
- mcpRegistry: MCPRegistry;
8
- documentSearch: (query: string) => Promise<{ reply: string; sources: any[] }>;
9
- maxIterations?: number;
10
- }
11
-
12
- export class MultiAgentCoordinator {
13
- private llmProvider: ILLMProvider;
14
- private mcpRegistry: MCPRegistry;
15
- private documentSearch: (query: string) => Promise<{ reply: string; sources: any[] }>;
16
- private maxIterations: number;
17
-
18
- constructor(options: CoordinatorOptions) {
19
- this.llmProvider = options.llmProvider;
20
- this.mcpRegistry = options.mcpRegistry;
21
- this.documentSearch = options.documentSearch;
22
- this.maxIterations = options.maxIterations ?? 5;
23
- }
24
-
25
- /**
26
- * Run the multi-agent coordination loop synchronously and return the final response.
27
- */
28
- async run(question: string, history: ChatMessage[] = []): Promise<ChatResponse> {
29
- const generator = this.runStream(question, history);
30
- let finalReply = '';
31
- const sources: any[] = [];
32
-
33
- for await (const chunk of generator) {
34
- if (typeof chunk === 'string') {
35
- finalReply += chunk;
36
- } else if (chunk && typeof chunk === 'object') {
37
- if ('reply' in chunk && chunk.reply) {
38
- finalReply += chunk.reply;
39
- }
40
- if ('sources' in chunk && chunk.sources) {
41
- sources.push(...chunk.sources);
42
- }
43
- }
44
- }
45
-
46
- return {
47
- reply: finalReply,
48
- sources,
49
- };
50
- }
51
-
52
- /**
53
- * Run the multi-agent coordination loop as an async stream, yielding intermediate thought blocks and tool execution events.
54
- */
55
- async *runStream(question: string, history: ChatMessage[] = []): AsyncGenerator<string | ChatResponse> {
56
- // 1. Gather all tools
57
- const mcpTools = await this.mcpRegistry.getAllTools();
58
-
59
- // Construct system instructions with tools
60
- let systemPrompt = `You are a goal-driven supervisor agent coordinating a RAG search engine and external MCP servers to solve the user's task.
61
- You must think step-by-step before acting. Write your internal thinking process inside a \`<think>...</think>\` block first, then act or answer.
62
-
63
- Available Tools:
64
- - document_search(query: string): Search the vector database and knowledge base for documents.
65
-
66
- ${mcpTools.length > 0 ? 'MCP Server Tools:' : ''}
67
- ${mcpTools.map(mt => `- ${mt.tool.name}(${JSON.stringify(mt.tool.inputSchema?.properties || {})}): ${mt.tool.description || 'No description provided.'}`).join('\n')}
68
-
69
- Tool Calling Protocol:
70
- If you need to call a tool, write:
71
- TOOL_CALL: <toolName>({ "argName": "value" })
72
- And then STOP generating immediately.
73
-
74
- Once you have gathered enough information to fully satisfy the user's query, write your final response directly after the closing \`</think>\` block.
75
- `;
76
-
77
- // 2. Setup message history for the supervisor
78
- const supervisorHistory: ChatMessage[] = [
79
- { role: 'system' as any, content: systemPrompt },
80
- ...history,
81
- { role: 'user', content: question }
82
- ];
83
-
84
- let iteration = 0;
85
- const allSources: any[] = [];
86
-
87
- while (iteration < this.maxIterations) {
88
- iteration++;
89
-
90
- const context = ''; // Context is populated by tool call results directly in message history
91
- let fullModelResponse = '';
92
- let textBuffer = '';
93
- let inThinking = false;
94
- let toolCallDetected: { name: string; args: any } | null = null;
95
-
96
- if (!this.llmProvider.chatStream) {
97
- // Fallback for non-streaming providers
98
- const reply = await this.llmProvider.chat(supervisorHistory, context);
99
- fullModelResponse = reply;
100
-
101
- // Parse simulated thinking / tool call
102
- const thinkIndex = reply.indexOf('<think>');
103
- const endThinkIndex = reply.indexOf('</think>');
104
-
105
- let thinkingText = '';
106
- let answerText = reply;
107
-
108
- if (thinkIndex !== -1 && endThinkIndex !== -1) {
109
- thinkingText = reply.substring(thinkIndex + 7, endThinkIndex);
110
- answerText = reply.substring(endThinkIndex + 8);
111
- yield { type: 'thinking', text: thinkingText } as any;
112
- }
113
-
114
- const toolMatch = answerText.match(/TOOL_CALL:\s*(\w+)\s*\(([\s\S]*)\)/);
115
- if (toolMatch) {
116
- const toolName = toolMatch[1];
117
- const toolArgsStr = toolMatch[2];
118
- try {
119
- const toolArgs = JSON.parse(toolArgsStr.trim());
120
- toolCallDetected = { name: toolName, args: toolArgs };
121
- } catch (e) {
122
- console.error('[MultiAgentCoordinator] Failed to parse tool args:', toolArgsStr, e);
123
- }
124
- } else {
125
- yield answerText;
126
- }
127
- } else {
128
- // Run with streaming completion
129
- const stream = this.llmProvider.chatStream(supervisorHistory, context);
130
-
131
- for await (const chunk of stream) {
132
- fullModelResponse += chunk;
133
- textBuffer += chunk;
134
-
135
- // Check for <think> tag
136
- if (!inThinking && textBuffer.includes('<think>')) {
137
- inThinking = true;
138
- const idx = textBuffer.indexOf('<think>');
139
- textBuffer = textBuffer.slice(idx + 7);
140
- }
141
-
142
- // Check for </think> tag
143
- if (inThinking && textBuffer.includes('</think>')) {
144
- inThinking = false;
145
- const idx = textBuffer.indexOf('</think>');
146
- const thinkingDelta = textBuffer.slice(0, idx);
147
- yield { type: 'thinking', text: thinkingDelta } as any;
148
- textBuffer = textBuffer.slice(idx + 8);
149
- }
150
-
151
- // If we are in thinking mode, yield thinking delta
152
- if (inThinking && textBuffer.length > 0) {
153
- yield { type: 'thinking', text: textBuffer } as any;
154
- textBuffer = '';
155
- }
156
-
157
- // Check for TOOL_CALL during stream
158
- if (!inThinking && textBuffer.includes('TOOL_CALL:')) {
159
- const idx = textBuffer.indexOf('TOOL_CALL:');
160
- const precedingText = textBuffer.slice(0, idx);
161
- if (precedingText.trim()) {
162
- yield precedingText;
163
- }
164
- // Await remainder of stream to get the full tool call signature
165
- textBuffer = textBuffer.slice(idx);
166
- }
167
-
168
- // If not in thinking and no tool call prefix is blocking, yield final answer text
169
- if (!inThinking && !textBuffer.includes('TOOL_CALL:') && textBuffer.length > 0) {
170
- yield textBuffer;
171
- textBuffer = '';
172
- }
173
- }
174
-
175
- // Flush any remaining buffer text
176
- if (textBuffer.trim()) {
177
- const toolMatch = textBuffer.match(/TOOL_CALL:\s*(\w+)\s*\(([\s\S]*)\)/);
178
- if (toolMatch) {
179
- const toolName = toolMatch[1];
180
- const toolArgsStr = toolMatch[2];
181
- try {
182
- const toolArgs = JSON.parse(toolArgsStr.trim());
183
- toolCallDetected = { name: toolName, args: toolArgs };
184
- } catch (e) {
185
- console.error('[MultiAgentCoordinator] Failed to parse tool args:', toolArgsStr, e);
186
- }
187
- } else {
188
- yield textBuffer;
189
- }
190
- }
191
- }
192
-
193
- // 3. Append the model response to the supervisor history
194
- supervisorHistory.push({ role: 'assistant', content: fullModelResponse });
195
-
196
- // 4. Handle tool execution if requested, else break the loop
197
- if (toolCallDetected) {
198
- const { name: toolName, args: toolArgs } = toolCallDetected;
199
-
200
- yield {
201
- type: 'thinking',
202
- text: `\n[Agent Call] Executing tool "${toolName}" with parameters ${JSON.stringify(toolArgs)}...\n`
203
- } as any;
204
-
205
- let toolResultText = '';
206
- try {
207
- if (toolName === 'document_search') {
208
- const searchRes = await this.documentSearch(toolArgs.query || '');
209
- toolResultText = `document_search returned:\n${searchRes.reply}\n\nSources count: ${searchRes.sources.length}`;
210
- if (searchRes.sources && searchRes.sources.length > 0) {
211
- allSources.push(...searchRes.sources);
212
- yield { reply: '', sources: searchRes.sources };
213
- }
214
- } else {
215
- // Call MCP tool
216
- const mcpRes = await this.mcpRegistry.callTool(toolName, toolArgs);
217
- toolResultText = `MCP Tool "${toolName}" returned:\n${JSON.stringify(mcpRes.content)}`;
218
- }
219
- } catch (err: any) {
220
- toolResultText = `Error calling tool "${toolName}": ${err.message}`;
221
- }
222
-
223
- // Append tool output to history
224
- supervisorHistory.push({
225
- role: 'user',
226
- content: `TOOL_RESULT for ${toolName}:\n${toolResultText}`
227
- });
228
-
229
- yield {
230
- type: 'thinking',
231
- text: `[Agent Output] Tool "${toolName}" executed. Continuing reasoning...\n`
232
- } as any;
233
- } else {
234
- // No tool call requested — response is complete
235
- break;
236
- }
237
- }
238
- }
239
- }