@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,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
- }