@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,29 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import { Moon, Sun } from 'lucide-react';
5
- import { useTheme } from 'next-themes';
6
- import { useHydrated } from '../hooks/useHydrated';
7
-
8
- export function ThemeToggle() {
9
- const { theme, setTheme } = useTheme();
10
- const mounted = useHydrated();
11
-
12
- if (!mounted) {
13
- return <div className="w-8 h-8 rounded-lg" />; // Placeholder to avoid layout shift
14
- }
15
-
16
- return (
17
- <button
18
- onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
19
- className="w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:text-slate-900 dark:text-white/40 dark:hover:text-white/70 hover:bg-slate-100 dark:hover:bg-white/10 transition-all"
20
- aria-label="Toggle theme"
21
- >
22
- {theme === 'dark' ? (
23
- <Sun className="w-4 h-4" />
24
- ) : (
25
- <Moon className="w-4 h-4" />
26
- )}
27
- </button>
28
- );
29
- }
@@ -1,75 +0,0 @@
1
- 'use client';
2
-
3
- import React, { useState, useEffect, useRef } from 'react';
4
- import { Brain, ChevronDown, ChevronRight, Loader2 } from 'lucide-react';
5
-
6
- interface ThinkingBlockProps {
7
- thinking: string;
8
- thinkingMs?: number;
9
- isStreaming?: boolean;
10
- }
11
-
12
- export function ThinkingBlock({ thinking, thinkingMs, isStreaming = false }: ThinkingBlockProps) {
13
- const [isExpanded, setIsExpanded] = useState(true);
14
- const containerRef = useRef<HTMLDivElement>(null);
15
-
16
- // Collapse by default when streaming finishes
17
- useEffect(() => {
18
- if (!isStreaming) {
19
- setIsExpanded(false);
20
- } else {
21
- setIsExpanded(true);
22
- }
23
- }, [isStreaming]);
24
-
25
- // Auto-scroll thinking container while streaming
26
- useEffect(() => {
27
- if (isStreaming && isExpanded && containerRef.current) {
28
- containerRef.current.scrollTop = containerRef.current.scrollHeight;
29
- }
30
- }, [thinking, isStreaming, isExpanded]);
31
-
32
- const durationSec = thinkingMs ? (thinkingMs / 1000).toFixed(1) : null;
33
-
34
- return (
35
- <div className="w-full max-w-2xl my-1.5 border border-slate-200 dark:border-white/10 rounded-xl bg-slate-50/50 dark:bg-white/5 overflow-hidden transition-all duration-200">
36
- {/* Header */}
37
- <button
38
- onClick={() => setIsExpanded(!isExpanded)}
39
- className="w-full px-4 py-2.5 flex items-center justify-between text-xs font-medium text-slate-500 dark:text-white/40 hover:bg-slate-100 dark:hover:bg-white/10 transition-colors cursor-pointer select-none"
40
- >
41
- <div className="flex items-center gap-2">
42
- {isStreaming ? (
43
- <Loader2 className="w-3.5 h-3.5 animate-spin text-slate-400 dark:text-white/30" />
44
- ) : (
45
- <Brain className="w-3.5 h-3.5 text-slate-400 dark:text-white/40" />
46
- )}
47
- <span>
48
- {isStreaming
49
- ? 'Thinking...'
50
- : durationSec
51
- ? `Thought for ${durationSec}s`
52
- : 'Thinking process'}
53
- </span>
54
- </div>
55
- <div>
56
- {isExpanded ? (
57
- <ChevronDown className="w-3.5 h-3.5 text-slate-400 dark:text-white/30" />
58
- ) : (
59
- <ChevronRight className="w-3.5 h-3.5 text-slate-400 dark:text-white/30" />
60
- )}
61
- </div>
62
- </button>
63
-
64
- {/* Body */}
65
- {isExpanded && (
66
- <div
67
- ref={containerRef}
68
- className="px-4 pb-3 pt-1 border-t border-slate-200 dark:border-white/10 text-xs font-mono leading-relaxed text-slate-600 dark:text-white/60 bg-slate-50/20 dark:bg-transparent max-h-60 overflow-y-auto whitespace-pre-wrap select-text break-words"
69
- >
70
- {thinking}
71
- </div>
72
- )}
73
- </div>
74
- );
75
- }
@@ -1,342 +0,0 @@
1
- import React from 'react';
2
- import { Product } from '../types';
3
- import { ChatViewportSize } from '../types/props';
4
- import { DynamicChart } from './DynamicChart';
5
- import { ProductCarousel } from './ProductCarousel';
6
- import { VisualizationRenderer } from './VisualizationRenderer';
7
- import { extractLikelyJsonBlock, sanitizeJson, resolveImage } from '../utils/ProductExtractor';
8
-
9
- // ─── Universal UI Dispatcher ────────────────────────────────────────────────
10
-
11
- interface UIConfig {
12
- view: 'chart' | 'carousel' | 'table' | 'none';
13
- chartType?: 'pie' | 'bar' | 'line';
14
- xAxisKey?: string;
15
- dataKeys?: string[];
16
- columns?: string[];
17
- colors?: string[];
18
- data: Record<string, unknown>[];
19
- title?: string;
20
- description?: string;
21
- insights?: string[];
22
- type?: string;
23
- items?: Record<string, unknown>[];
24
- rows?: Record<string, unknown>[];
25
- products?: Record<string, unknown>[];
26
- results?: Record<string, unknown>[];
27
-
28
- // V7 Protocol Fields
29
- carousel?: {
30
- items: Record<string, unknown>[];
31
- };
32
- chart?: {
33
- type: 'pie' | 'bar' | 'line';
34
- xKey: string;
35
- yKeys: string[];
36
- data: Record<string, unknown>[];
37
- };
38
- table?: {
39
- columns: string[];
40
- rows?: Record<string, unknown>[];
41
- data?: Record<string, unknown>[];
42
- };
43
- }
44
-
45
- interface RawUIConfig extends Omit<UIConfig, 'data' | 'items' | 'rows' | 'products' | 'results' | 'carousel' | 'chart' | 'table'> {
46
- data: Array<Record<string, unknown> | unknown[]>;
47
- items?: Array<Record<string, unknown> | unknown[]>;
48
- rows?: Array<Record<string, unknown> | unknown[]>;
49
- products?: Array<Record<string, unknown> | unknown[]>;
50
- results?: Array<Record<string, unknown> | unknown[]>;
51
-
52
- // V7 Protocol Fields (Raw)
53
- carousel?: {
54
- items: Array<Record<string, unknown> | unknown[]>;
55
- };
56
- chart?: {
57
- type: 'pie' | 'bar' | 'line';
58
- xKey: string;
59
- yKeys: string[];
60
- data: Array<Record<string, unknown> | unknown[]>;
61
- };
62
- table?: {
63
- columns: string[];
64
- rows?: Array<Record<string, unknown> | unknown[]>;
65
- data?: Array<Record<string, unknown> | unknown[]>;
66
- };
67
- }
68
-
69
- function normalizeTabularRows(
70
- rows: Array<Record<string, unknown> | unknown[]> | undefined,
71
- columns?: string[],
72
- ): Record<string, unknown>[] {
73
- if (!Array.isArray(rows)) return [];
74
-
75
- // Common synonyms for mapping natural language headers to technical keys
76
- const SYNONYMS: Record<string, string[]> = {
77
- name: ['product', 'item', 'title', 'label', 'heading', 'product name', 'item name'],
78
- price: ['cost', 'amount', 'msrp', 'price', 'rate', 'value', 'price_usd'],
79
- brand: ['manufacturer', 'vendor', 'make', 'company', 'brand_name', 'supplier'],
80
- image: ['imageUrl', 'thumbnail', 'img', 'url', 'photo', 'picture', 'media'],
81
- stock: ['inventory', 'quantity', 'count', 'availability', 'stock_level', 'in stock', 'status'],
82
- };
83
-
84
- return rows
85
- .map((row) => {
86
- if (Array.isArray(row)) {
87
- const keys = Array.isArray(columns) && columns.length > 0
88
- ? columns
89
- : row.map((_, index) => `column_${index + 1}`);
90
-
91
- return keys.reduce<Record<string, unknown>>((acc, key, index) => {
92
- acc[key] = row[index];
93
- return acc;
94
- }, {});
95
- }
96
-
97
- if (row && typeof row === 'object') {
98
- const result: Record<string, unknown> = { ...row };
99
-
100
- // Self-Healing: If columns are provided, ensure the row has keys matching those columns
101
- if (Array.isArray(columns)) {
102
- columns.forEach(col => {
103
- if (result[col] !== undefined) return; // Already matches
104
-
105
- // Try to find a match among row keys
106
- const rowKeys = Object.keys(row);
107
- const colLower = col.toLowerCase().replace(/_/g, ' ');
108
-
109
- // 1. Direct case-insensitive / space-to-underscore match
110
- const foundKey = rowKeys.find(rk => {
111
- const rkLower = rk.toLowerCase().replace(/_/g, ' ');
112
- return rkLower === colLower || rkLower.includes(colLower) || colLower.includes(rkLower);
113
- });
114
-
115
- if (foundKey) {
116
- result[col] = row[foundKey];
117
- return;
118
- }
119
-
120
- // 2. Synonym match
121
- for (const [target, aliases] of Object.entries(SYNONYMS)) {
122
- const isMatch = target === colLower || aliases.some(a => colLower.includes(a) || a.includes(colLower));
123
- if (isMatch) {
124
- const mappedKey = rowKeys.find(rk => {
125
- const rkL = rk.toLowerCase();
126
- return rkL === target || aliases.some(a => rkL.includes(a) || a.includes(rkL));
127
- });
128
- if (mappedKey) {
129
- result[col] = row[mappedKey];
130
- break;
131
- }
132
- }
133
- }
134
- });
135
- }
136
-
137
- return result;
138
- }
139
-
140
- return { value: row };
141
- })
142
- .filter((row) => Object.keys(row).length > 0);
143
- }
144
-
145
- function resolveStructuredRows(config: Partial<RawUIConfig> & Record<string, unknown>) {
146
- // V7 Nested Structures
147
- if (config.carousel?.items && Array.isArray(config.carousel.items)) return config.carousel.items;
148
- if (config.chart?.data && Array.isArray(config.chart.data)) return config.chart.data;
149
- if (config.table?.rows && Array.isArray(config.table.rows)) return config.table.rows;
150
- if (config.table?.data && Array.isArray(config.table.data)) return config.table.data;
151
-
152
- // V6 Flat Structures
153
- if (Array.isArray(config.data) && config.data.length > 0) return config.data;
154
- if (Array.isArray(config.items) && config.items.length > 0) return config.items;
155
- if (Array.isArray(config.products) && config.products.length > 0) return config.products;
156
- if (Array.isArray(config.rows) && config.rows.length > 0) return config.rows;
157
- if (Array.isArray(config.results) && config.results.length > 0) return config.results;
158
- return [];
159
- }
160
-
161
- export function UIDispatcher({ rawContent, primaryColor, accentColor, isStreaming, onAddToCart, viewportSize = 'large' }: {
162
- rawContent: string;
163
- primaryColor?: string;
164
- accentColor?: string;
165
- isStreaming?: boolean;
166
- onAddToCart?: (product: Product) => void;
167
- viewportSize?: ChatViewportSize;
168
- }) {
169
- //console.log('rawContent', rawContent);
170
- const result = React.useMemo<{ config: UIConfig } | { error: string } | { loading: true }>(() => {
171
- try {
172
- const clean = rawContent
173
- .replace(/^```[a-z]*\s*/i, '')
174
- .replace(/```\s*$/, '')
175
- .trim();
176
- const parsed = JSON.parse(sanitizeJson(extractLikelyJsonBlock(clean)));
177
- const config = { ...parsed } as Partial<RawUIConfig> & Record<string, unknown>;
178
-
179
- // V7 Field Mapping
180
- if (config.chart) {
181
- if (!config.chartType) config.chartType = config.chart.type;
182
- if (!config.xAxisKey) config.xAxisKey = config.chart.xKey;
183
- if (!config.dataKeys) config.dataKeys = config.chart.yKeys;
184
- }
185
- if (config.table) {
186
- if (!config.columns) config.columns = config.table.columns;
187
- }
188
-
189
- const resolvedRows = resolveStructuredRows(config);
190
-
191
- // ─── Intent Healing & Auto-Detection ───────────────────────────────────
192
-
193
- const hasProductLikeData = resolvedRows.length > 0 &&
194
- typeof resolvedRows[0] === 'object' && resolvedRows[0] !== null &&
195
- !Array.isArray(resolvedRows[0]) &&
196
- (['price', 'brand', 'image', 'link', 'thumbnail'].some(key => key in resolvedRows[0]) ||
197
- Object.keys(resolvedRows[0]).length >= 4);
198
-
199
- const hasAggregationLikeData = resolvedRows.length > 0 &&
200
- typeof resolvedRows[0] === 'object' && resolvedRows[0] !== null &&
201
- !Array.isArray(resolvedRows[0]) &&
202
- (['value', 'count', 'total', 'percentage'].some(key => key in resolvedRows[0]) ||
203
- (Object.keys(resolvedRows[0]).length <= 3 && Object.values(resolvedRows[0]).some(v => typeof v === 'number')));
204
-
205
- // 1. Healing: Override explicit view if it contradicts the data shape
206
- if (config.view === 'chart' && hasProductLikeData && !hasAggregationLikeData) {
207
- config.view = 'carousel';
208
- } else if (config.view === 'carousel' && hasAggregationLikeData && !hasProductLikeData) {
209
- config.view = 'chart';
210
- config.chartType = (config.chartType as 'pie' | 'bar' | 'line') || 'bar';
211
- }
212
-
213
- // 2. Auto-Detection: Fill in missing or dynamic view
214
- if (!config.view || ['pie', 'bar', 'line', 'pie_chart', 'bar_chart', 'line_chart'].includes(String(config.view))) {
215
- const viewStr = String(config.view || '').toLowerCase();
216
-
217
- if (viewStr.includes('carousel') || config.type === 'products' || Array.isArray(config.items) || hasProductLikeData) {
218
- config.view = 'carousel';
219
- } else if (
220
- viewStr.includes('chart') ||
221
- viewStr.includes('pie') || viewStr.includes('bar') || viewStr.includes('line') ||
222
- hasAggregationLikeData ||
223
- (typeof config.type === 'string' && ['pie', 'bar', 'line'].includes(config.type)) ||
224
- (typeof config.chartType === 'string' && ['pie', 'bar', 'line'].includes(config.chartType))
225
- ) {
226
- config.view = 'chart';
227
- config.chartType = (config.chartType as 'pie' | 'bar' | 'line') ||
228
- (viewStr.replace('_chart', '') as 'pie' | 'bar' | 'line') ||
229
- (config.type as 'pie' | 'bar' | 'line') || 'bar';
230
- } else if (viewStr.includes('table') || config.type === 'table') {
231
- config.view = 'table';
232
- } else {
233
- // Do not forcefully default to a table if it is not explicitly requested or strongly implied
234
- config.view = 'none';
235
- }
236
- }
237
-
238
- const normalizedConfig: UIConfig = {
239
- ...(config as Omit<UIConfig, 'data'>),
240
- data: normalizeTabularRows(resolvedRows, config.columns),
241
- };
242
-
243
- return { config: normalizedConfig };
244
- } catch (err) {
245
- if (isStreaming) return { loading: true };
246
- return { error: String(err) };
247
- }
248
- }, [rawContent, isStreaming]);
249
-
250
- if ('loading' in result) {
251
- return (
252
- <div className="my-4 p-8 bg-slate-50 dark:bg-white/5 rounded-xl border border-dashed border-slate-300 dark:border-white/10 flex flex-col items-center justify-center gap-3 animate-pulse">
253
- <div className="w-5 h-5 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin" />
254
- <p className="text-xs text-slate-500 font-medium italic">Preparing view...</p>
255
- </div>
256
- );
257
- }
258
-
259
- if ('error' in result) {
260
- return <pre className="p-4 my-2 bg-slate-900 text-slate-100 rounded-lg text-[10px] overflow-auto max-h-40"><code>{rawContent}</code></pre>;
261
- }
262
-
263
- const { config } = result;
264
- const isCompact = viewportSize === 'compact';
265
- const hasInsights = Array.isArray(config.insights) && config.insights.length > 0;
266
- const hasDescription = typeof config.description === 'string' && config.description.trim().length > 0;
267
-
268
- switch (config.view) {
269
- case 'chart':
270
- return (
271
- <div className={`${isCompact ? 'my-4 p-3' : 'my-6 p-4'} bg-white dark:bg-slate-900 rounded-2xl border border-slate-200 dark:border-white/10 shadow-sm overflow-hidden`}>
272
- {config.title && <h4 className={`${isCompact ? 'text-[11px] mb-3' : 'text-xs mb-4'} font-semibold text-slate-500 px-2`}>{config.title}</h4>}
273
- {hasDescription && (
274
- <p className={`px-2 ${isCompact ? 'text-xs' : 'text-sm'} text-slate-500 dark:text-white/60`}>{config.description}</p>
275
- )}
276
- <DynamicChart
277
- config={{
278
- type: (config.chartType || 'bar') as 'bar' | 'line' | 'pie',
279
- data: config.data as unknown as Record<string, string | number>[],
280
- xAxisKey: config.xAxisKey,
281
- dataKeys: config.dataKeys,
282
- colors: config.colors,
283
- }}
284
- primaryColor={primaryColor}
285
- accentColor={accentColor}
286
- viewportSize={viewportSize}
287
- isStreaming={isStreaming}
288
- />
289
- {hasInsights && (
290
- <div className="mt-4 flex flex-wrap gap-2 px-2">
291
- {config.insights?.map((insight, i) => (
292
- <span
293
- key={`insight-${i}`}
294
- className={`rounded-full border border-emerald-200 bg-emerald-50 ${isCompact ? 'px-2.5 py-1 text-[10px]' : 'px-3 py-1 text-[11px]'} font-medium text-emerald-700 dark:border-emerald-500/20 dark:bg-emerald-500/10 dark:text-emerald-300`}
295
- >
296
- {String(insight)}
297
- </span>
298
- ))}
299
- </div>
300
- )}
301
- </div>
302
- );
303
- case 'carousel':
304
- return (
305
- <div className="my-4">
306
- {config.title && <h4 className={`${isCompact ? 'mb-1.5 text-[11px]' : 'mb-2 text-xs'} font-semibold text-slate-500`}>{config.title}</h4>}
307
- {hasDescription && (
308
- <p className={`mb-3 ${isCompact ? 'text-xs' : 'text-sm'} text-slate-500 dark:text-white/60`}>{config.description}</p>
309
- )}
310
- <ProductCarousel products={(config.data as unknown as Product[]).map(item => ({
311
- ...item,
312
- image: item.image ?? (typeof resolveImage === 'function' ? resolveImage(item as unknown as Record<string, unknown>) : undefined)
313
- }))} primaryColor={primaryColor} onAddToCart={onAddToCart} />
314
- </div>
315
- );
316
- case 'table':
317
- return (
318
- <div className={`${isCompact ? 'my-3 p-3 max-h-[320px]' : 'my-4 p-4 max-h-[400px]'} bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm overflow-auto`}>
319
- {config.title && <h4 className={`${isCompact ? 'text-[11px]' : 'text-xs'} font-semibold text-slate-500 mb-2`}>{config.title}</h4>}
320
- {hasDescription && (
321
- <p className={`mb-3 ${isCompact ? 'text-xs' : 'text-sm'} text-slate-500 dark:text-white/60`}>{config.description}</p>
322
- )}
323
- {/* Use VisualizationRenderer for Table data */}
324
- <VisualizationRenderer
325
- data={{
326
- type: 'table',
327
- title: config.title || '',
328
- description: config.description,
329
- data: {
330
- columns: config.columns || Object.keys(config.data[0] || {}),
331
- rows: config.data.map(row => Object.values(row)) as (string | number | boolean)[][]
332
- }
333
- }}
334
- primaryColor={primaryColor}
335
- isStreaming={isStreaming}
336
- />
337
- </div>
338
- );
339
- default:
340
- return null;
341
- }
342
- }