@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.
- package/README.md +22 -0
- package/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-BGslIR5l.d.mts} +65 -4
- package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-C3gY6kZ0.d.ts} +65 -4
- package/dist/handlers/index.js +668 -837
- package/dist/handlers/index.mjs +678 -837
- package/dist/index.css +5 -0
- package/dist/index.d.mts +4 -28
- package/dist/index.d.ts +4 -28
- package/dist/index.js +91 -43
- package/dist/index.min.css +1 -1
- package/dist/index.mjs +91 -43
- package/dist/server.d.mts +21 -7
- package/dist/server.d.ts +21 -7
- package/dist/server.js +731 -875
- package/dist/server.mjs +741 -875
- package/package.json +11 -4
- package/src/LicensedRetrivora.ts +0 -278
- package/src/app/api/chat/route.ts +0 -4
- package/src/app/api/health/route.ts +0 -5
- package/src/app/api/ingest/route.ts +0 -27
- package/src/app/api/suggestions/route.ts +0 -5
- package/src/app/api/upload/route.ts +0 -5
- package/src/app/constants.tsx +0 -270
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -449
- package/src/app/layout.tsx +0 -22
- package/src/app/page.tsx +0 -64
- package/src/app/types.ts +0 -30
- package/src/browser.tsx +0 -127
- package/src/components/ChatWidget.tsx +0 -393
- package/src/components/ChatWindow.tsx +0 -952
- package/src/components/CodeViewer.tsx +0 -56
- package/src/components/ConfigProvider.tsx +0 -141
- package/src/components/DocumentUpload.tsx +0 -354
- package/src/components/DynamicChart.tsx +0 -297
- package/src/components/HourglassLoader.tsx +0 -87
- package/src/components/MarkdownComponents.tsx +0 -186
- package/src/components/MessageBubble.tsx +0 -498
- package/src/components/ObservabilityPanel.tsx +0 -374
- package/src/components/ProductCard.tsx +0 -107
- package/src/components/ProductCarousel.tsx +0 -97
- package/src/components/SourceCard.tsx +0 -61
- package/src/components/ThemeProvider.tsx +0 -8
- package/src/components/ThemeToggle.tsx +0 -29
- package/src/components/ThinkingBlock.tsx +0 -75
- package/src/components/UIDispatcher.tsx +0 -342
- package/src/components/VisualizationRenderer.tsx +0 -621
- package/src/components/constants.tsx +0 -503
- package/src/config/ConfigBuilder.ts +0 -285
- package/src/config/EmbeddingStrategy.ts +0 -148
- package/src/config/LicenseConfigResolver.ts +0 -298
- package/src/config/RagConfig.ts +0 -328
- package/src/config/UniversalProfiles.ts +0 -82
- package/src/config/constants.ts +0 -64
- package/src/config/serverConfig.ts +0 -378
- package/src/config/uiConstants.ts +0 -47
- package/src/core/BatchProcessor.ts +0 -385
- package/src/core/CircuitBreaker.ts +0 -118
- package/src/core/ConfigFetcher.ts +0 -220
- package/src/core/ConfigResolver.ts +0 -165
- package/src/core/ConfigValidator.ts +0 -197
- package/src/core/DatabaseStorage.ts +0 -526
- package/src/core/FreeTierLimitsGuard.ts +0 -281
- package/src/core/LLMRouter.ts +0 -79
- package/src/core/LangChainAgent.ts +0 -132
- package/src/core/LicenseValidator.ts +0 -284
- package/src/core/LicenseVerifier.ts +0 -261
- package/src/core/MultiAgentCoordinator.ts +0 -239
- package/src/core/Pipeline.ts +0 -1279
- package/src/core/PluginManager.ts +0 -277
- package/src/core/ProjectSettings.ts +0 -247
- package/src/core/ProviderHealthCheck.ts +0 -133
- package/src/core/ProviderInterfaces.ts +0 -37
- package/src/core/ProviderRegistry.ts +0 -156
- package/src/core/QueryProcessor.ts +0 -399
- package/src/core/Retrivora.ts +0 -98
- package/src/core/VectorPlugin.ts +0 -193
- package/src/core/mcp.ts +0 -261
- package/src/exceptions/index.ts +0 -131
- package/src/handlers/index.ts +0 -1625
- package/src/hooks/useHydrated.ts +0 -13
- package/src/hooks/useProjectSettings.ts +0 -105
- package/src/hooks/useRagChat.ts +0 -436
- package/src/hooks/useStoredMessages.ts +0 -64
- package/src/index.css +0 -4269
- package/src/index.ts +0 -137
- package/src/lib/plugin.ts +0 -24
- package/src/llm/ILLMProvider.ts +0 -60
- package/src/llm/LLMFactory.ts +0 -141
- package/src/llm/providers/AnthropicProvider.ts +0 -215
- package/src/llm/providers/GeminiProvider.ts +0 -311
- package/src/llm/providers/GroqProvider.ts +0 -184
- package/src/llm/providers/OllamaProvider.ts +0 -232
- package/src/llm/providers/OpenAIProvider.ts +0 -188
- package/src/llm/providers/QwenProvider.ts +0 -199
- package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
- package/src/llm/utils.ts +0 -46
- package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
- package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
- package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
- package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
- package/src/providers/vectordb/MilvusProvider.ts +0 -134
- package/src/providers/vectordb/MongoDBProvider.ts +0 -250
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
- package/src/providers/vectordb/PineconeProvider.ts +0 -295
- package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
- package/src/providers/vectordb/QdrantProvider.ts +0 -294
- package/src/providers/vectordb/RedisProvider.ts +0 -105
- package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
- package/src/providers/vectordb/WeaviateProvider.ts +0 -172
- package/src/rag/DocumentChunker.ts +0 -144
- package/src/rag/EntityExtractor.ts +0 -90
- package/src/rag/LlamaIndexIngestor.ts +0 -60
- package/src/rag/Reranker.ts +0 -106
- package/src/rendering/IntentClassifier.ts +0 -167
- package/src/rendering/RendererRegistry.ts +0 -164
- package/src/rendering/RuleEngine.ts +0 -67
- package/src/rendering/VisualizationDecisionEngine.ts +0 -164
- package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
- package/src/rendering/index.ts +0 -12
- package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
- package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
- package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
- package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
- package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
- package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
- package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
- package/src/rendering/types.ts +0 -96
- package/src/server.ts +0 -156
- package/src/tailwind.css +0 -194
- package/src/telemetry/TelemetryService.ts +0 -330
- package/src/types/chat.ts +0 -89
- package/src/types/index.ts +0 -278
- package/src/types/pdf-parse.d.ts +0 -13
- package/src/types/props.ts +0 -169
- package/src/utils/DocumentParser.ts +0 -111
- package/src/utils/ProductExtractor.ts +0 -350
- package/src/utils/SchemaMapper.ts +0 -176
- package/src/utils/UITransformer.ts +0 -1812
- package/src/utils/synonyms.ts +0 -80
- package/src/utils/templateUtils.ts +0 -78
- package/src/version.ts +0 -6
|
@@ -1,621 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
PieChart,
|
|
6
|
-
Pie,
|
|
7
|
-
Cell,
|
|
8
|
-
BarChart,
|
|
9
|
-
Bar,
|
|
10
|
-
LineChart,
|
|
11
|
-
Line,
|
|
12
|
-
ScatterChart,
|
|
13
|
-
Scatter,
|
|
14
|
-
XAxis,
|
|
15
|
-
YAxis,
|
|
16
|
-
CartesianGrid,
|
|
17
|
-
Tooltip,
|
|
18
|
-
Legend,
|
|
19
|
-
ResponsiveContainer,
|
|
20
|
-
RadarChart,
|
|
21
|
-
Radar,
|
|
22
|
-
PolarGrid,
|
|
23
|
-
PolarAngleAxis,
|
|
24
|
-
PolarRadiusAxis,
|
|
25
|
-
} from 'recharts';
|
|
26
|
-
import { ProductCarousel } from './ProductCarousel';
|
|
27
|
-
import {
|
|
28
|
-
Product,
|
|
29
|
-
UITransformationResponse,
|
|
30
|
-
VisualizationType,
|
|
31
|
-
PieChartData,
|
|
32
|
-
BarChartData,
|
|
33
|
-
LineChartDataPoint,
|
|
34
|
-
ScatterPlotDataPoint,
|
|
35
|
-
MetricCardData,
|
|
36
|
-
TableData,
|
|
37
|
-
CarouselProduct,
|
|
38
|
-
} from '../types';
|
|
39
|
-
|
|
40
|
-
import { CHART_COLORS } from './DynamicChart';
|
|
41
|
-
|
|
42
|
-
function getColor(index: number): string {
|
|
43
|
-
return CHART_COLORS[index % CHART_COLORS.length];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function stripLeakedAnswerWrappers(raw: string): string {
|
|
47
|
-
return raw
|
|
48
|
-
.replace(/<prose\s+answer(?:\s+in\s+[^>]*)?>\s*([\s\S]*?)\s*<\/prose>/gi, '$1')
|
|
49
|
-
.replace(/<\/?prose(?:\s+answer)?[^>]*>/gi, '')
|
|
50
|
-
.trim();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ─── Custom Tooltip ───────────────────────────────────────────────────────────
|
|
54
|
-
|
|
55
|
-
interface TooltipPayloadItem {
|
|
56
|
-
name: string;
|
|
57
|
-
value: string | number;
|
|
58
|
-
color?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function CustomTooltip({
|
|
62
|
-
active,
|
|
63
|
-
payload,
|
|
64
|
-
label,
|
|
65
|
-
}: {
|
|
66
|
-
active?: boolean;
|
|
67
|
-
payload?: TooltipPayloadItem[];
|
|
68
|
-
label?: string;
|
|
69
|
-
}) {
|
|
70
|
-
if (!active || !payload || payload.length === 0) return null;
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<div className="rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs shadow-xl dark:border-white/10 dark:bg-slate-950">
|
|
74
|
-
{label && (
|
|
75
|
-
<p className="mb-2 font-semibold text-slate-800 dark:text-white/90">{label}</p>
|
|
76
|
-
)}
|
|
77
|
-
{payload.map((entry, i) => (
|
|
78
|
-
<div key={i} className="flex items-center justify-between gap-3 text-slate-600 dark:text-white/70">
|
|
79
|
-
<span className="flex items-center gap-1.5">
|
|
80
|
-
{entry.color && (
|
|
81
|
-
<span
|
|
82
|
-
className="inline-block w-2 h-2 rounded-full flex-shrink-0"
|
|
83
|
-
style={{ background: entry.color }}
|
|
84
|
-
/>
|
|
85
|
-
)}
|
|
86
|
-
{entry.name}
|
|
87
|
-
</span>
|
|
88
|
-
<span className="font-medium text-slate-900 dark:text-white/90">{entry.value}</span>
|
|
89
|
-
</div>
|
|
90
|
-
))}
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ─── Props ────────────────────────────────────────────────────────────────────
|
|
96
|
-
|
|
97
|
-
interface VisualizationRendererProps {
|
|
98
|
-
data: UITransformationResponse;
|
|
99
|
-
className?: string;
|
|
100
|
-
primaryColor?: string;
|
|
101
|
-
onAddToCart?: (product: Product) => void;
|
|
102
|
-
isStreaming?: boolean;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ─── Main component ───────────────────────────────────────────────────────────
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* VisualizationRenderer — Renders UI transformations as React components.
|
|
109
|
-
*
|
|
110
|
-
* Dynamically selects the appropriate visualization component based on the
|
|
111
|
-
* transformation type returned by UITransformer. All charts are rendered via
|
|
112
|
-
* Recharts (chart.js has been removed).
|
|
113
|
-
*
|
|
114
|
-
* Supported types: bar_chart · line_chart · pie_chart · table · product_carousel · text
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* const transformation = await UITransformer.analyzeAndDecide(query, sources, llm);
|
|
118
|
-
* return <VisualizationRenderer data={transformation} />;
|
|
119
|
-
*/
|
|
120
|
-
export function VisualizationRenderer({
|
|
121
|
-
data,
|
|
122
|
-
className = '',
|
|
123
|
-
primaryColor,
|
|
124
|
-
onAddToCart,
|
|
125
|
-
isStreaming,
|
|
126
|
-
}: VisualizationRendererProps) {
|
|
127
|
-
if (!data) {
|
|
128
|
-
return (
|
|
129
|
-
<div className={`p-4 text-gray-500 ${className}`}>
|
|
130
|
-
No data available for visualization
|
|
131
|
-
</div>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<div className={`space-y-4 ${className}`}>
|
|
137
|
-
<div className="space-y-1">
|
|
138
|
-
<h3 className="text-sm font-semibold text-slate-900 dark:text-white">
|
|
139
|
-
{data.title}
|
|
140
|
-
</h3>
|
|
141
|
-
{data.description && data.description !== (data.data as { content?: string })?.content && (
|
|
142
|
-
<p className="text-xs text-slate-500 dark:text-slate-400">
|
|
143
|
-
{data.description}
|
|
144
|
-
</p>
|
|
145
|
-
)}
|
|
146
|
-
</div>
|
|
147
|
-
|
|
148
|
-
{renderVisualization(data.type, data.data, onAddToCart, primaryColor, isStreaming)}
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ─── Visualization dispatcher ─────────────────────────────────────────────────
|
|
154
|
-
|
|
155
|
-
function renderVisualization(
|
|
156
|
-
type: VisualizationType,
|
|
157
|
-
data: unknown,
|
|
158
|
-
onAddToCart?: (product: Product) => void,
|
|
159
|
-
primaryColor?: string,
|
|
160
|
-
isStreaming?: boolean,
|
|
161
|
-
): React.ReactNode {
|
|
162
|
-
try {
|
|
163
|
-
switch (type) {
|
|
164
|
-
case 'pie_chart':
|
|
165
|
-
return <PieChartView data={data as PieChartData[]} isStreaming={isStreaming} />;
|
|
166
|
-
case 'bar_chart':
|
|
167
|
-
return <BarChartView data={data as BarChartData[]} primaryColor={primaryColor} isStreaming={isStreaming} />;
|
|
168
|
-
case 'histogram':
|
|
169
|
-
return <BarChartView data={data as BarChartData[]} primaryColor={primaryColor} isStreaming={isStreaming} />;
|
|
170
|
-
case 'horizontal_bar':
|
|
171
|
-
return <BarChartView data={data as BarChartData[]} primaryColor={primaryColor} isStreaming={isStreaming} layout="vertical" />;
|
|
172
|
-
case 'line_chart':
|
|
173
|
-
return <LineChartView data={data as LineChartDataPoint[]} primaryColor={primaryColor} isStreaming={isStreaming} />;
|
|
174
|
-
case 'scatter_plot':
|
|
175
|
-
return <ScatterPlotView data={data as ScatterPlotDataPoint[]} primaryColor={primaryColor} isStreaming={isStreaming} />;
|
|
176
|
-
case 'radar_chart':
|
|
177
|
-
return <RadarChartView data={data as Record<string, unknown>[]} isStreaming={isStreaming} />;
|
|
178
|
-
case 'metric_card':
|
|
179
|
-
return <MetricCardView data={data as MetricCardData} isStreaming={isStreaming} />;
|
|
180
|
-
case 'geo_map':
|
|
181
|
-
return <BarChartView data={data as BarChartData[]} primaryColor={primaryColor} isStreaming={isStreaming} />;
|
|
182
|
-
case 'table':
|
|
183
|
-
return <TableView data={data as TableData} isStreaming={isStreaming} />;
|
|
184
|
-
case 'product_carousel':
|
|
185
|
-
case 'carousel':
|
|
186
|
-
// Show skeleton while streaming so the user sees an indicator immediately
|
|
187
|
-
if (isStreaming) return <CarouselSkeleton />;
|
|
188
|
-
return <CarouselView data={data as CarouselProduct[]} onAddToCart={onAddToCart} primaryColor={primaryColor} />;
|
|
189
|
-
|
|
190
|
-
case 'text':
|
|
191
|
-
default:
|
|
192
|
-
return <TextView data={data} />;
|
|
193
|
-
}
|
|
194
|
-
} catch (error) {
|
|
195
|
-
console.warn('[VisualizationRenderer] Rendering failed, falling back to text:', error);
|
|
196
|
-
return <TextView data={{ content: 'Unable to render the requested visualization.' }} />;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// ─── Carousel Skeleton ───────────────────────────────────────────────────────
|
|
201
|
-
|
|
202
|
-
function CarouselSkeleton() {
|
|
203
|
-
return (
|
|
204
|
-
<div className="w-full py-2">
|
|
205
|
-
<div className="mb-3 h-4 w-36 rounded-full bg-slate-200 animate-pulse" />
|
|
206
|
-
<div className="flex gap-3 overflow-hidden">
|
|
207
|
-
{Array.from({ length: 4 }).map((_, i) => (
|
|
208
|
-
<div
|
|
209
|
-
key={i}
|
|
210
|
-
className="flex-shrink-0 w-44 rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden animate-pulse"
|
|
211
|
-
>
|
|
212
|
-
<div className="h-28 bg-slate-100" />
|
|
213
|
-
<div className="p-3 space-y-2">
|
|
214
|
-
<div className="h-3 w-28 rounded-full bg-slate-200" />
|
|
215
|
-
<div className="h-3 w-16 rounded-full bg-slate-100" />
|
|
216
|
-
<div className="h-3 w-20 rounded-full bg-emerald-100" />
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
219
|
-
))}
|
|
220
|
-
</div>
|
|
221
|
-
</div>
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function ChartSkeleton({ type }: { type: 'pie' | 'bar' | 'table' }) {
|
|
226
|
-
if (type === 'pie') {
|
|
227
|
-
return (
|
|
228
|
-
<div className="w-full mt-4 mb-2 animate-pulse">
|
|
229
|
-
<div className="mx-auto w-40 h-40 rounded-full bg-slate-100 dark:bg-white/10" />
|
|
230
|
-
</div>
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
if (type === 'table') {
|
|
234
|
-
return (
|
|
235
|
-
<div className="w-full mt-4 mb-2 animate-pulse space-y-2">
|
|
236
|
-
<div className="h-8 bg-slate-100 dark:bg-white/10 rounded" />
|
|
237
|
-
<div className="h-8 bg-slate-100 dark:bg-white/10 rounded" />
|
|
238
|
-
<div className="h-8 bg-slate-100 dark:bg-white/10 rounded" />
|
|
239
|
-
</div>
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
return (
|
|
243
|
-
<div className="w-full mt-4 mb-2 animate-pulse flex items-end gap-2 h-32 px-2">
|
|
244
|
-
{Array.from({ length: 5 }).map((_, i) => (
|
|
245
|
-
<div key={i} className="flex-1 rounded-t-md bg-slate-100 dark:bg-white/10" style={{ height: `${40 + (i % 3) * 25}%` }} />
|
|
246
|
-
))}
|
|
247
|
-
</div>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// ─── Pie Chart ────────────────────────────────────────────────────────────────
|
|
252
|
-
|
|
253
|
-
function PieChartView({ data, isStreaming }: { data: PieChartData[]; isStreaming?: boolean }) {
|
|
254
|
-
if (isStreaming) return <ChartSkeleton type="pie" />;
|
|
255
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
256
|
-
return <div className="text-xs text-red-500">Invalid pie chart data</div>;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Recharts Pie uses flat key/value, so map to { name, value }
|
|
260
|
-
const chartData = data.map((item) => ({
|
|
261
|
-
name: item.label,
|
|
262
|
-
value: item.value,
|
|
263
|
-
inStockCount: item.inStockCount,
|
|
264
|
-
outOfStockCount: item.outOfStockCount,
|
|
265
|
-
}));
|
|
266
|
-
const hasStockBreakdown = chartData.some(
|
|
267
|
-
(item) => item.inStockCount !== undefined || item.outOfStockCount !== undefined,
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
return (
|
|
271
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm">
|
|
272
|
-
<ResponsiveContainer width="100%" height={280}>
|
|
273
|
-
<PieChart>
|
|
274
|
-
<Pie
|
|
275
|
-
data={chartData}
|
|
276
|
-
dataKey="value"
|
|
277
|
-
nameKey="name"
|
|
278
|
-
cx="50%"
|
|
279
|
-
cy="50%"
|
|
280
|
-
outerRadius="68%"
|
|
281
|
-
label={false}
|
|
282
|
-
labelLine={false}
|
|
283
|
-
>
|
|
284
|
-
{chartData.map((_entry, index) => (
|
|
285
|
-
<Cell key={`cell-${index}`} fill={getColor(index)} />
|
|
286
|
-
))}
|
|
287
|
-
</Pie>
|
|
288
|
-
<Tooltip content={<CustomTooltip />} />
|
|
289
|
-
<Legend wrapperStyle={{ fontSize: 12 }} verticalAlign="bottom" />
|
|
290
|
-
</PieChart>
|
|
291
|
-
</ResponsiveContainer>
|
|
292
|
-
{hasStockBreakdown && (
|
|
293
|
-
<div className="mt-3 grid gap-2 sm:grid-cols-2">
|
|
294
|
-
{chartData.map((item, index) => {
|
|
295
|
-
const inStock = Number(item.inStockCount ?? 0);
|
|
296
|
-
const outOfStock = Number(item.outOfStockCount ?? 0);
|
|
297
|
-
const status = inStock > 0 ? `${inStock} in stock` : 'Out of stock';
|
|
298
|
-
const mutedStatus = outOfStock > 0 ? `${outOfStock} out` : null;
|
|
299
|
-
|
|
300
|
-
return (
|
|
301
|
-
<div
|
|
302
|
-
key={item.name}
|
|
303
|
-
className="flex min-w-0 items-center justify-between gap-3 rounded-md border border-slate-100 px-2.5 py-2 text-xs dark:border-white/10"
|
|
304
|
-
>
|
|
305
|
-
<span className="flex min-w-0 items-center gap-2 text-slate-700 dark:text-white/75">
|
|
306
|
-
<span
|
|
307
|
-
className="h-2.5 w-2.5 flex-shrink-0 rounded-full"
|
|
308
|
-
style={{ background: getColor(index) }}
|
|
309
|
-
/>
|
|
310
|
-
<span className="truncate">{item.name}</span>
|
|
311
|
-
</span>
|
|
312
|
-
<span className={inStock > 0 ? 'whitespace-nowrap font-medium text-emerald-600' : 'whitespace-nowrap font-medium text-rose-600'}>
|
|
313
|
-
{status}
|
|
314
|
-
{mutedStatus && <span className="ml-1 text-slate-400">({mutedStatus})</span>}
|
|
315
|
-
</span>
|
|
316
|
-
</div>
|
|
317
|
-
);
|
|
318
|
-
})}
|
|
319
|
-
</div>
|
|
320
|
-
)}
|
|
321
|
-
</div>
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// ─── Bar Chart ────────────────────────────────────────────────────────────────
|
|
326
|
-
|
|
327
|
-
function BarChartView({
|
|
328
|
-
data,
|
|
329
|
-
primaryColor,
|
|
330
|
-
isStreaming,
|
|
331
|
-
layout = 'horizontal',
|
|
332
|
-
}: {
|
|
333
|
-
data: BarChartData[];
|
|
334
|
-
primaryColor?: string;
|
|
335
|
-
isStreaming?: boolean;
|
|
336
|
-
layout?: 'horizontal' | 'vertical';
|
|
337
|
-
}) {
|
|
338
|
-
if (isStreaming) return <ChartSkeleton type="bar" />;
|
|
339
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
340
|
-
return <div className="text-xs text-red-500">Invalid bar chart data</div>;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const chartData = data.map((item) => ({
|
|
344
|
-
category: item.category,
|
|
345
|
-
value: item.value,
|
|
346
|
-
...(item.inStockCount !== undefined && { inStockCount: item.inStockCount }),
|
|
347
|
-
...(item.outOfStockCount !== undefined && { outOfStockCount: item.outOfStockCount }),
|
|
348
|
-
}));
|
|
349
|
-
|
|
350
|
-
const barColor = primaryColor ?? getColor(0);
|
|
351
|
-
const hasStock = chartData.some((d) => 'inStockCount' in d);
|
|
352
|
-
|
|
353
|
-
return (
|
|
354
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm overflow-x-auto">
|
|
355
|
-
<ResponsiveContainer width="100%" height={260}>
|
|
356
|
-
<BarChart
|
|
357
|
-
data={chartData}
|
|
358
|
-
layout={layout}
|
|
359
|
-
margin={{ top: 10, right: 10, left: layout === 'vertical' ? 20 : -20, bottom: 0 }}
|
|
360
|
-
>
|
|
361
|
-
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
|
|
362
|
-
{layout === 'vertical' ? (
|
|
363
|
-
<>
|
|
364
|
-
<XAxis type="number" tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
|
|
365
|
-
<YAxis type="category" dataKey="category" width={110} tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={false} />
|
|
366
|
-
</>
|
|
367
|
-
) : (
|
|
368
|
-
<>
|
|
369
|
-
<XAxis
|
|
370
|
-
dataKey="category"
|
|
371
|
-
tick={{ fontSize: 11, fill: '#64748b' }}
|
|
372
|
-
tickLine={false}
|
|
373
|
-
axisLine={{ stroke: '#cbd5e1' }}
|
|
374
|
-
/>
|
|
375
|
-
<YAxis tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={false} />
|
|
376
|
-
</>
|
|
377
|
-
)}
|
|
378
|
-
<Tooltip content={<CustomTooltip />} cursor={{ fill: '#f1f5f9' }} />
|
|
379
|
-
<Legend wrapperStyle={{ fontSize: 12 }} />
|
|
380
|
-
{hasStock ? (
|
|
381
|
-
<>
|
|
382
|
-
<Bar dataKey="inStockCount" name="In Stock" fill={getColor(1)} radius={[4, 4, 0, 0]} />
|
|
383
|
-
<Bar dataKey="outOfStockCount" name="Out of Stock" fill={getColor(3)} radius={[4, 4, 0, 0]} />
|
|
384
|
-
</>
|
|
385
|
-
) : (
|
|
386
|
-
<Bar dataKey="value" name="Value" fill={barColor} radius={[4, 4, 0, 0]} />
|
|
387
|
-
)}
|
|
388
|
-
</BarChart>
|
|
389
|
-
</ResponsiveContainer>
|
|
390
|
-
</div>
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// ─── Scatter Plot ─────────────────────────────────────────────────────────────
|
|
395
|
-
|
|
396
|
-
function ScatterPlotView({ data, primaryColor, isStreaming }: { data: ScatterPlotDataPoint[]; primaryColor?: string; isStreaming?: boolean }) {
|
|
397
|
-
if (isStreaming) return <ChartSkeleton type="bar" />;
|
|
398
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
399
|
-
return <div className="text-xs text-red-500">Invalid scatter plot data</div>;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return (
|
|
403
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm overflow-x-auto">
|
|
404
|
-
<ResponsiveContainer width="100%" height={260}>
|
|
405
|
-
<ScatterChart margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
|
|
406
|
-
<CartesianGrid strokeDasharray="3 3" stroke="#e2e8f0" />
|
|
407
|
-
<XAxis type="number" dataKey="x" tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
|
|
408
|
-
<YAxis type="number" dataKey="y" tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={false} />
|
|
409
|
-
<Tooltip content={<CustomTooltip />} cursor={{ strokeDasharray: '3 3' }} />
|
|
410
|
-
<Scatter name="Value" data={data} fill={primaryColor ?? getColor(0)} />
|
|
411
|
-
</ScatterChart>
|
|
412
|
-
</ResponsiveContainer>
|
|
413
|
-
</div>
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// ─── Metric Card ──────────────────────────────────────────────────────────────
|
|
418
|
-
|
|
419
|
-
function MetricCardView({ data, isStreaming }: { data: MetricCardData; isStreaming?: boolean }) {
|
|
420
|
-
if (isStreaming) return <ChartSkeleton type="bar" />;
|
|
421
|
-
if (!data || typeof data.value !== 'number') {
|
|
422
|
-
return <div className="text-xs text-red-500">Invalid metric data</div>;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return (
|
|
426
|
-
<div className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-slate-900">
|
|
427
|
-
<div className="text-xs font-medium uppercase text-slate-500 dark:text-slate-400">{data.label}</div>
|
|
428
|
-
<div className="mt-2 text-3xl font-semibold text-slate-900 dark:text-white">
|
|
429
|
-
{data.value.toLocaleString()}
|
|
430
|
-
{data.unit && <span className="ml-1 text-base text-slate-500">{data.unit}</span>}
|
|
431
|
-
</div>
|
|
432
|
-
{data.operation && (
|
|
433
|
-
<div className="mt-1 text-xs text-slate-500 dark:text-slate-400">{data.operation}</div>
|
|
434
|
-
)}
|
|
435
|
-
</div>
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// ─── Line Chart ───────────────────────────────────────────────────────────────
|
|
440
|
-
|
|
441
|
-
function LineChartView({ data, primaryColor, isStreaming }: { data: LineChartDataPoint[]; primaryColor?: string; isStreaming?: boolean }) {
|
|
442
|
-
if (isStreaming) return <ChartSkeleton type="bar" />;
|
|
443
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
444
|
-
return <div className="text-xs text-red-500">Invalid line chart data</div>;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
const chartData = data.map((point) => ({
|
|
448
|
-
label: String(point.label ?? point.timestamp),
|
|
449
|
-
value: Number(point.value),
|
|
450
|
-
}));
|
|
451
|
-
|
|
452
|
-
const lineColor = primaryColor ?? getColor(0);
|
|
453
|
-
|
|
454
|
-
return (
|
|
455
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm overflow-x-auto">
|
|
456
|
-
<ResponsiveContainer width="100%" height={260}>
|
|
457
|
-
<LineChart data={chartData} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
|
|
458
|
-
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
|
|
459
|
-
<XAxis
|
|
460
|
-
dataKey="label"
|
|
461
|
-
tick={{ fontSize: 11, fill: '#64748b' }}
|
|
462
|
-
tickLine={false}
|
|
463
|
-
axisLine={{ stroke: '#cbd5e1' }}
|
|
464
|
-
/>
|
|
465
|
-
<YAxis tick={{ fontSize: 11, fill: '#64748b' }} tickLine={false} axisLine={false} />
|
|
466
|
-
<Tooltip content={<CustomTooltip />} />
|
|
467
|
-
<Line
|
|
468
|
-
type="monotone"
|
|
469
|
-
dataKey="value"
|
|
470
|
-
name="Value"
|
|
471
|
-
stroke={lineColor}
|
|
472
|
-
strokeWidth={2.5}
|
|
473
|
-
dot={{ r: 3.5, strokeWidth: 2, fill: lineColor }}
|
|
474
|
-
activeDot={{ r: 5 }}
|
|
475
|
-
/>
|
|
476
|
-
</LineChart>
|
|
477
|
-
</ResponsiveContainer>
|
|
478
|
-
</div>
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// ─── Radar Chart ──────────────────────────────────────────────────────────────
|
|
483
|
-
|
|
484
|
-
function RadarChartView({ data, isStreaming }: { data: Record<string, unknown>[]; isStreaming?: boolean }) {
|
|
485
|
-
if (isStreaming) return <ChartSkeleton type="pie" />;
|
|
486
|
-
if (!Array.isArray(data) || data.length === 0) {
|
|
487
|
-
return <div className="text-xs text-red-500">Invalid radar chart data</div>;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Find all keys that are not 'attribute' to use as radar data keys (product names)
|
|
491
|
-
const productNames = Array.from(
|
|
492
|
-
new Set(data.flatMap((item) => Object.keys(item).filter((key) => key !== 'attribute')))
|
|
493
|
-
);
|
|
494
|
-
|
|
495
|
-
return (
|
|
496
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm">
|
|
497
|
-
<ResponsiveContainer width="100%" height={300}>
|
|
498
|
-
<RadarChart cx="50%" cy="50%" outerRadius="80%" data={data}>
|
|
499
|
-
<PolarGrid stroke="#e2e8f0" />
|
|
500
|
-
<PolarAngleAxis dataKey="attribute" tick={{ fontSize: 11, fill: '#64748b' }} />
|
|
501
|
-
<PolarRadiusAxis tick={{ fontSize: 10, fill: '#64748b' }} />
|
|
502
|
-
{productNames.map((productName, index) => (
|
|
503
|
-
<Radar
|
|
504
|
-
key={productName}
|
|
505
|
-
name={productName}
|
|
506
|
-
dataKey={productName}
|
|
507
|
-
stroke={getColor(index)}
|
|
508
|
-
fill={getColor(index)}
|
|
509
|
-
fillOpacity={0.4}
|
|
510
|
-
/>
|
|
511
|
-
))}
|
|
512
|
-
<Tooltip content={<CustomTooltip />} />
|
|
513
|
-
<Legend wrapperStyle={{ fontSize: 12 }} />
|
|
514
|
-
</RadarChart>
|
|
515
|
-
</ResponsiveContainer>
|
|
516
|
-
</div>
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// ─── Table ────────────────────────────────────────────────────────────────────
|
|
521
|
-
|
|
522
|
-
function TableView({ data, isStreaming }: { data: TableData; isStreaming?: boolean }) {
|
|
523
|
-
if (isStreaming) return <ChartSkeleton type="table" />;
|
|
524
|
-
if (!data?.columns || !data?.rows) {
|
|
525
|
-
return <div className="text-xs text-red-500">Invalid table data</div>;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return (
|
|
529
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm overflow-hidden">
|
|
530
|
-
<div className="overflow-x-auto">
|
|
531
|
-
<table className="w-full text-sm border-collapse">
|
|
532
|
-
<thead className="bg-slate-50 dark:bg-white/5 border-b border-slate-200 dark:border-white/10">
|
|
533
|
-
<tr>
|
|
534
|
-
{data.columns.map((col: string, idx: number) => (
|
|
535
|
-
<th
|
|
536
|
-
key={idx}
|
|
537
|
-
className="px-4 py-3 text-left text-xs font-semibold text-slate-700 dark:text-white/90 whitespace-nowrap uppercase tracking-wider"
|
|
538
|
-
>
|
|
539
|
-
{col}
|
|
540
|
-
</th>
|
|
541
|
-
))}
|
|
542
|
-
</tr>
|
|
543
|
-
</thead>
|
|
544
|
-
<tbody className="divide-y divide-slate-100 dark:divide-white/5">
|
|
545
|
-
{data.rows.map((row: (string | number | boolean)[], rowIdx: number) => (
|
|
546
|
-
<tr
|
|
547
|
-
key={rowIdx}
|
|
548
|
-
className="hover:bg-slate-50/60 dark:hover:bg-white/5 transition-colors"
|
|
549
|
-
>
|
|
550
|
-
{row.map((cell: string | number | boolean, cellIdx: number) => (
|
|
551
|
-
<td
|
|
552
|
-
key={cellIdx}
|
|
553
|
-
className="px-4 py-3 text-slate-600 dark:text-white/70 text-sm"
|
|
554
|
-
>
|
|
555
|
-
{String(cell)}
|
|
556
|
-
</td>
|
|
557
|
-
))}
|
|
558
|
-
</tr>
|
|
559
|
-
))}
|
|
560
|
-
</tbody>
|
|
561
|
-
</table>
|
|
562
|
-
</div>
|
|
563
|
-
<div className="px-4 py-2 bg-slate-50 dark:bg-white/5 border-t border-slate-100 dark:border-white/5">
|
|
564
|
-
<p className="text-[11px] text-slate-400 dark:text-white/30">
|
|
565
|
-
{data.rows.length} row{data.rows.length !== 1 ? 's' : ''}
|
|
566
|
-
</p>
|
|
567
|
-
</div>
|
|
568
|
-
</div>
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
// ─── Product Carousel ─────────────────────────────────────────────────────────
|
|
573
|
-
|
|
574
|
-
function CarouselView({
|
|
575
|
-
data,
|
|
576
|
-
onAddToCart,
|
|
577
|
-
primaryColor,
|
|
578
|
-
}: {
|
|
579
|
-
data: CarouselProduct[];
|
|
580
|
-
onAddToCart?: (product: Product) => void;
|
|
581
|
-
primaryColor?: string;
|
|
582
|
-
}) {
|
|
583
|
-
if (!Array.isArray(data)) {
|
|
584
|
-
return <div className="text-xs text-red-500">Invalid carousel data</div>;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const products: Product[] = data.map((product) => ({
|
|
588
|
-
id: product.id,
|
|
589
|
-
name: product.name,
|
|
590
|
-
brand: product.brand,
|
|
591
|
-
price: product.price,
|
|
592
|
-
image: product.image,
|
|
593
|
-
link: typeof product.link === 'string' ? product.link : undefined,
|
|
594
|
-
description: product.description,
|
|
595
|
-
inStock: product.inStock,
|
|
596
|
-
}));
|
|
597
|
-
|
|
598
|
-
return (
|
|
599
|
-
<div className="w-full">
|
|
600
|
-
<ProductCarousel
|
|
601
|
-
products={products}
|
|
602
|
-
primaryColor={primaryColor ?? '#6366f1'}
|
|
603
|
-
onAddToCart={(p) => onAddToCart?.(p)}
|
|
604
|
-
/>
|
|
605
|
-
</div>
|
|
606
|
-
);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// ─── Text / Prose ─────────────────────────────────────────────────────────────
|
|
610
|
-
|
|
611
|
-
function TextView({ data }: { data: unknown }) {
|
|
612
|
-
const content = stripLeakedAnswerWrappers((data as { content?: string })?.content || String(data ?? ''));
|
|
613
|
-
|
|
614
|
-
return (
|
|
615
|
-
<div className="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 p-4 shadow-sm">
|
|
616
|
-
<p className="text-sm text-slate-700 dark:text-slate-300 whitespace-pre-wrap leading-relaxed">
|
|
617
|
-
{content}
|
|
618
|
-
</p>
|
|
619
|
-
</div>
|
|
620
|
-
);
|
|
621
|
-
}
|