@retrivora-ai/rag-engine 2.4.3 → 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 (139) 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 +27 -4
  4. package/dist/handlers/index.mjs +27 -4
  5. package/dist/index.d.mts +3 -3
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +12 -10
  8. package/dist/index.mjs +12 -10
  9. package/dist/server.d.mts +2 -2
  10. package/dist/server.d.ts +2 -2
  11. package/dist/server.js +28 -4
  12. package/dist/server.mjs +28 -4
  13. package/package.json +1 -3
  14. package/src/LicensedRetrivora.ts +0 -278
  15. package/src/app/api/chat/route.ts +0 -4
  16. package/src/app/api/health/route.ts +0 -5
  17. package/src/app/api/ingest/route.ts +0 -27
  18. package/src/app/api/suggestions/route.ts +0 -5
  19. package/src/app/api/upload/route.ts +0 -5
  20. package/src/app/constants.tsx +0 -270
  21. package/src/app/favicon.ico +0 -0
  22. package/src/app/globals.css +0 -449
  23. package/src/app/layout.tsx +0 -22
  24. package/src/app/page.tsx +0 -64
  25. package/src/app/types.ts +0 -30
  26. package/src/browser.tsx +0 -127
  27. package/src/components/ChatWidget.tsx +0 -393
  28. package/src/components/ChatWindow.tsx +0 -952
  29. package/src/components/CodeViewer.tsx +0 -56
  30. package/src/components/ConfigProvider.tsx +0 -141
  31. package/src/components/DocumentUpload.tsx +0 -354
  32. package/src/components/DynamicChart.tsx +0 -297
  33. package/src/components/HourglassLoader.tsx +0 -87
  34. package/src/components/MarkdownComponents.tsx +0 -186
  35. package/src/components/MessageBubble.tsx +0 -498
  36. package/src/components/ObservabilityPanel.tsx +0 -374
  37. package/src/components/ProductCard.tsx +0 -107
  38. package/src/components/ProductCarousel.tsx +0 -97
  39. package/src/components/SourceCard.tsx +0 -61
  40. package/src/components/ThemeProvider.tsx +0 -8
  41. package/src/components/ThemeToggle.tsx +0 -29
  42. package/src/components/ThinkingBlock.tsx +0 -75
  43. package/src/components/UIDispatcher.tsx +0 -342
  44. package/src/components/VisualizationRenderer.tsx +0 -621
  45. package/src/components/constants.tsx +0 -503
  46. package/src/config/ConfigBuilder.ts +0 -285
  47. package/src/config/EmbeddingStrategy.ts +0 -148
  48. package/src/config/LicenseConfigResolver.ts +0 -298
  49. package/src/config/RagConfig.ts +0 -328
  50. package/src/config/UniversalProfiles.ts +0 -82
  51. package/src/config/constants.ts +0 -64
  52. package/src/config/serverConfig.ts +0 -378
  53. package/src/config/uiConstants.ts +0 -47
  54. package/src/core/BatchProcessor.ts +0 -385
  55. package/src/core/CircuitBreaker.ts +0 -118
  56. package/src/core/ConfigFetcher.ts +0 -220
  57. package/src/core/ConfigResolver.ts +0 -165
  58. package/src/core/ConfigValidator.ts +0 -197
  59. package/src/core/DatabaseStorage.ts +0 -526
  60. package/src/core/FreeTierLimitsGuard.ts +0 -281
  61. package/src/core/LLMRouter.ts +0 -79
  62. package/src/core/LangChainAgent.ts +0 -132
  63. package/src/core/LicenseValidator.ts +0 -284
  64. package/src/core/LicenseVerifier.ts +0 -261
  65. package/src/core/MultiAgentCoordinator.ts +0 -239
  66. package/src/core/Pipeline.ts +0 -1279
  67. package/src/core/PluginManager.ts +0 -277
  68. package/src/core/ProjectSettings.ts +0 -247
  69. package/src/core/ProviderHealthCheck.ts +0 -133
  70. package/src/core/ProviderInterfaces.ts +0 -37
  71. package/src/core/ProviderRegistry.ts +0 -156
  72. package/src/core/QueryProcessor.ts +0 -399
  73. package/src/core/Retrivora.ts +0 -98
  74. package/src/core/VectorPlugin.ts +0 -193
  75. package/src/core/mcp.ts +0 -261
  76. package/src/exceptions/index.ts +0 -131
  77. package/src/handlers/index.ts +0 -1625
  78. package/src/hooks/useHydrated.ts +0 -13
  79. package/src/hooks/useProjectSettings.ts +0 -105
  80. package/src/hooks/useRagChat.ts +0 -436
  81. package/src/hooks/useStoredMessages.ts +0 -64
  82. package/src/index.css +0 -4269
  83. package/src/index.ts +0 -137
  84. package/src/lib/plugin.ts +0 -24
  85. package/src/llm/ILLMProvider.ts +0 -60
  86. package/src/llm/LLMFactory.ts +0 -141
  87. package/src/llm/providers/AnthropicProvider.ts +0 -215
  88. package/src/llm/providers/GeminiProvider.ts +0 -311
  89. package/src/llm/providers/GroqProvider.ts +0 -184
  90. package/src/llm/providers/OllamaProvider.ts +0 -232
  91. package/src/llm/providers/OpenAIProvider.ts +0 -188
  92. package/src/llm/providers/QwenProvider.ts +0 -199
  93. package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
  94. package/src/llm/utils.ts +0 -46
  95. package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
  96. package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
  97. package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
  98. package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
  99. package/src/providers/vectordb/MilvusProvider.ts +0 -134
  100. package/src/providers/vectordb/MongoDBProvider.ts +0 -250
  101. package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
  102. package/src/providers/vectordb/PineconeProvider.ts +0 -295
  103. package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
  104. package/src/providers/vectordb/QdrantProvider.ts +0 -294
  105. package/src/providers/vectordb/RedisProvider.ts +0 -105
  106. package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
  107. package/src/providers/vectordb/WeaviateProvider.ts +0 -172
  108. package/src/rag/DocumentChunker.ts +0 -144
  109. package/src/rag/EntityExtractor.ts +0 -90
  110. package/src/rag/LlamaIndexIngestor.ts +0 -60
  111. package/src/rag/Reranker.ts +0 -106
  112. package/src/rendering/IntentClassifier.ts +0 -167
  113. package/src/rendering/RendererRegistry.ts +0 -164
  114. package/src/rendering/RuleEngine.ts +0 -67
  115. package/src/rendering/VisualizationDecisionEngine.ts +0 -164
  116. package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
  117. package/src/rendering/index.ts +0 -12
  118. package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
  119. package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
  120. package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
  121. package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
  122. package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
  123. package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
  124. package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
  125. package/src/rendering/types.ts +0 -96
  126. package/src/server.ts +0 -156
  127. package/src/tailwind.css +0 -194
  128. package/src/telemetry/TelemetryService.ts +0 -330
  129. package/src/types/chat.ts +0 -89
  130. package/src/types/index.ts +0 -278
  131. package/src/types/pdf-parse.d.ts +0 -13
  132. package/src/types/props.ts +0 -169
  133. package/src/utils/DocumentParser.ts +0 -111
  134. package/src/utils/ProductExtractor.ts +0 -350
  135. package/src/utils/SchemaMapper.ts +0 -176
  136. package/src/utils/UITransformer.ts +0 -1812
  137. package/src/utils/synonyms.ts +0 -80
  138. package/src/utils/templateUtils.ts +0 -78
  139. 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
- }