@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,297 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
BarChart, Bar, LineChart, Line, PieChart, Pie, Cell,
|
|
6
|
-
XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer
|
|
7
|
-
} from 'recharts';
|
|
8
|
-
import { ChatViewportSize } from '../types/props';
|
|
9
|
-
|
|
10
|
-
export interface ChartConfig {
|
|
11
|
-
type: 'bar' | 'line' | 'pie';
|
|
12
|
-
data: Array<Record<string, string | number>>;
|
|
13
|
-
xAxisKey?: string;
|
|
14
|
-
dataKeys?: string[];
|
|
15
|
-
colors?: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface DynamicChartProps {
|
|
19
|
-
config: ChartConfig;
|
|
20
|
-
primaryColor?: string;
|
|
21
|
-
accentColor?: string;
|
|
22
|
-
viewportSize?: ChatViewportSize;
|
|
23
|
-
/** When true, renders a shimmer skeleton instead of the chart. */
|
|
24
|
-
isStreaming?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Shared palette — imported by VisualizationRenderer to avoid duplication. */
|
|
28
|
-
export const CHART_COLORS = ['#6366f1', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899'];
|
|
29
|
-
|
|
30
|
-
export function DynamicChart({
|
|
31
|
-
config,
|
|
32
|
-
primaryColor = '#6366f1',
|
|
33
|
-
accentColor = '#8b5cf6',
|
|
34
|
-
viewportSize = 'large',
|
|
35
|
-
isStreaming = false,
|
|
36
|
-
}: DynamicChartProps) {
|
|
37
|
-
const { type, data } = config;
|
|
38
|
-
const colors = config.colors || [primaryColor, accentColor, ...CHART_COLORS];
|
|
39
|
-
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
40
|
-
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
41
|
-
|
|
42
|
-
React.useEffect(() => {
|
|
43
|
-
const element = containerRef.current;
|
|
44
|
-
if (!element || typeof ResizeObserver === 'undefined') return;
|
|
45
|
-
|
|
46
|
-
const updateWidth = (width: number) => {
|
|
47
|
-
setContainerWidth(Math.round(width));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const observer = new ResizeObserver(([entry]) => {
|
|
51
|
-
if (!entry) return;
|
|
52
|
-
updateWidth(entry.contentRect.width);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
updateWidth(element.getBoundingClientRect().width);
|
|
56
|
-
observer.observe(element);
|
|
57
|
-
|
|
58
|
-
return () => observer.disconnect();
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
const isTiny = containerWidth > 0 && containerWidth < 300;
|
|
62
|
-
const isCompact = viewportSize === 'compact' || (containerWidth > 0 && containerWidth < 420);
|
|
63
|
-
const isMedium = !isCompact && (viewportSize === 'medium' || (containerWidth > 0 && containerWidth < 640));
|
|
64
|
-
const pieOuterRadius = isTiny ? '54%' : isCompact ? '60%' : isMedium ? '66%' : '72%';
|
|
65
|
-
const axisTick = { fontSize: isTiny ? 9 : isCompact ? 10 : 12, fill: '#64748b' };
|
|
66
|
-
const showLegend = !isTiny;
|
|
67
|
-
const truncateAxisLabel = (value: string | number) => {
|
|
68
|
-
const text = String(value);
|
|
69
|
-
const maxLength = isTiny ? 6 : isCompact ? 10 : 16;
|
|
70
|
-
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
|
71
|
-
};
|
|
72
|
-
const chartMargin = isTiny
|
|
73
|
-
? { top: 8, right: 4, left: -28, bottom: 0 }
|
|
74
|
-
: isCompact
|
|
75
|
-
? { top: 10, right: 6, left: -24, bottom: 0 }
|
|
76
|
-
: { top: 10, right: 10, left: -20, bottom: 0 };
|
|
77
|
-
|
|
78
|
-
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
79
|
-
// This prevents the "Objects are not valid as a React child" error in Tooltips/Legends
|
|
80
|
-
// This hook MUST be called before any early returns to satisfy React rules
|
|
81
|
-
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
82
|
-
// Also ensures numeric strings are converted to actual numbers for Recharts.
|
|
83
|
-
const sanitizedData = React.useMemo(() => {
|
|
84
|
-
if (!data) return [];
|
|
85
|
-
return data.map(item => {
|
|
86
|
-
const newItem: Record<string, string | number | null> = {};
|
|
87
|
-
Object.keys(item).forEach(k => {
|
|
88
|
-
const val = item[k];
|
|
89
|
-
if (Array.isArray(val)) {
|
|
90
|
-
val.forEach(subItem => {
|
|
91
|
-
if (typeof subItem === 'object' && subItem !== null) {
|
|
92
|
-
Object.keys(subItem).forEach(sk => {
|
|
93
|
-
const subVal = (subItem as Record<string, unknown>)[sk];
|
|
94
|
-
if (typeof subVal !== 'object' || subVal === null) {
|
|
95
|
-
// Auto-convert numeric strings
|
|
96
|
-
if (typeof subVal === 'string' && !isNaN(Number(subVal)) && subVal.trim() !== '') {
|
|
97
|
-
newItem[sk] = Number(subVal);
|
|
98
|
-
} else {
|
|
99
|
-
newItem[sk] = subVal as string | number | null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
} else if (typeof val !== 'object' || val === null) {
|
|
106
|
-
// Auto-convert numeric strings
|
|
107
|
-
if (typeof val === 'string' && !isNaN(Number(val)) && val.trim() !== '') {
|
|
108
|
-
newItem[k] = Number(val);
|
|
109
|
-
} else {
|
|
110
|
-
newItem[k] = val as string | number | null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return newItem;
|
|
115
|
-
});
|
|
116
|
-
}, [data]);
|
|
117
|
-
|
|
118
|
-
if (isStreaming) {
|
|
119
|
-
const bars = type === 'pie' ? 6 : 5;
|
|
120
|
-
return (
|
|
121
|
-
<div className="w-full mt-4 mb-2 animate-pulse">
|
|
122
|
-
{type === 'pie' ? (
|
|
123
|
-
<div className="mx-auto w-40 h-40 rounded-full bg-slate-100 dark:bg-white/10" />
|
|
124
|
-
) : (
|
|
125
|
-
<div className="flex items-end gap-2 h-32 px-2">
|
|
126
|
-
{Array.from({ length: bars }).map((_, i) => (
|
|
127
|
-
<div
|
|
128
|
-
key={i}
|
|
129
|
-
className="flex-1 rounded-t-md bg-slate-100 dark:bg-white/10"
|
|
130
|
-
style={{ height: `${40 + (i % 3) * 25}%` }}
|
|
131
|
-
/>
|
|
132
|
-
))}
|
|
133
|
-
</div>
|
|
134
|
-
)}
|
|
135
|
-
</div>
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!data || data.length === 0) {
|
|
140
|
-
return <div className="p-4 text-sm text-slate-500">No data available for chart.</div>;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Smart key resolution: if the provided keys don't exist in the data, try to guess them
|
|
144
|
-
const firstItem = sanitizedData[0];
|
|
145
|
-
const allKeys = Object.keys(firstItem);
|
|
146
|
-
|
|
147
|
-
// Resolve xAxisKey: use provided, fallback to 'name', 'label', 'category', or the first string key
|
|
148
|
-
const resolvedXKey = config.xAxisKey && firstItem[config.xAxisKey] !== undefined
|
|
149
|
-
? config.xAxisKey
|
|
150
|
-
: allKeys.find(k => k.toLowerCase() === 'name' || k.toLowerCase() === 'label' || k.toLowerCase() === 'category')
|
|
151
|
-
|| allKeys.find(k => typeof firstItem[k] === 'string')
|
|
152
|
-
|| allKeys[0];
|
|
153
|
-
|
|
154
|
-
// Resolve dataKeys: use provided, fallback to 'value', 'count', 'amount', or all numeric keys
|
|
155
|
-
const resolvedDataKeys = config.dataKeys && config.dataKeys.every(k => {
|
|
156
|
-
const val = firstItem[k];
|
|
157
|
-
return val !== undefined && typeof val !== 'object';
|
|
158
|
-
})
|
|
159
|
-
? config.dataKeys
|
|
160
|
-
: allKeys.filter(k => {
|
|
161
|
-
const val = firstItem[k];
|
|
162
|
-
return k !== resolvedXKey && (typeof val === 'number' || k.toLowerCase() === 'value' || k.toLowerCase() === 'count');
|
|
163
|
-
})
|
|
164
|
-
.slice(0, 5); // Limit to 5 series for sanity
|
|
165
|
-
|
|
166
|
-
// Final sanity check: ensure all keys are strings
|
|
167
|
-
const finalXKey = String(resolvedXKey);
|
|
168
|
-
const finalDataKeys = resolvedDataKeys.map(String).filter(k => k !== 'undefined');
|
|
169
|
-
const pieDataKey = finalDataKeys[0] || 'value';
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const tooltipLabelMap: Record<string, string> = {
|
|
173
|
-
value: 'Total Items',
|
|
174
|
-
count: 'Count',
|
|
175
|
-
inStockCount: 'In Stock',
|
|
176
|
-
outOfStockCount: 'Out of Stock',
|
|
177
|
-
stockStatus: 'Status',
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const renderTooltip = (
|
|
181
|
-
row: Record<string, string | number | null> | null,
|
|
182
|
-
label?: string,
|
|
183
|
-
) => {
|
|
184
|
-
if (!row) return null;
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
<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">
|
|
188
|
-
<p className="mb-2 font-semibold text-slate-800 dark:text-white/90">
|
|
189
|
-
{String(row[finalXKey] ?? label ?? 'Details')}
|
|
190
|
-
</p>
|
|
191
|
-
{Object.entries(row).map(([key, value]) => {
|
|
192
|
-
if (value === null || value === undefined || key === finalXKey) return null;
|
|
193
|
-
if (typeof value === 'object') return null;
|
|
194
|
-
|
|
195
|
-
// Filter out technical Recharts/internal keys
|
|
196
|
-
const forbiddenKeys = ['fill', 'color', 'payload', 'percent', 'stroke', 'inStock'];
|
|
197
|
-
if (forbiddenKeys.includes(key)) return null;
|
|
198
|
-
|
|
199
|
-
return (
|
|
200
|
-
<div key={key} className="flex items-center justify-between gap-3 text-slate-600 dark:text-white/70">
|
|
201
|
-
<span>{tooltipLabelMap[key] ?? key}</span>
|
|
202
|
-
<span className="font-medium text-slate-900 dark:text-white/90">{String(value)}</span>
|
|
203
|
-
</div>
|
|
204
|
-
);
|
|
205
|
-
})}
|
|
206
|
-
</div>
|
|
207
|
-
);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const getTooltipRow = (payload: unknown): Record<string, string | number | null> | null => {
|
|
211
|
-
if (!Array.isArray(payload) || payload.length === 0) return null;
|
|
212
|
-
const first = payload[0];
|
|
213
|
-
if (!first || typeof first !== 'object' || !('payload' in first)) return null;
|
|
214
|
-
|
|
215
|
-
const row = (first as { payload?: unknown }).payload;
|
|
216
|
-
if (!row || typeof row !== 'object' || Array.isArray(row)) return null;
|
|
217
|
-
|
|
218
|
-
return row as Record<string, string | number | null>;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// Handle Pie Chart separately as it has a different structure
|
|
222
|
-
if (type === 'pie') {
|
|
223
|
-
return (
|
|
224
|
-
<div ref={containerRef} className="w-full min-w-0 mt-4 mb-2 select-none overflow-hidden">
|
|
225
|
-
<div className="mx-auto w-full max-w-full aspect-square">
|
|
226
|
-
<ResponsiveContainer width="100%" height="100%">
|
|
227
|
-
<PieChart>
|
|
228
|
-
<Pie
|
|
229
|
-
data={sanitizedData}
|
|
230
|
-
dataKey={pieDataKey}
|
|
231
|
-
nameKey={finalXKey}
|
|
232
|
-
cx="50%"
|
|
233
|
-
cy="50%"
|
|
234
|
-
outerRadius={pieOuterRadius}
|
|
235
|
-
label={false}
|
|
236
|
-
labelLine={false}
|
|
237
|
-
>
|
|
238
|
-
{sanitizedData.map((_entry, index) => (
|
|
239
|
-
<Cell key={`cell-${index}`} fill={colors[index % colors.length]} />
|
|
240
|
-
))}
|
|
241
|
-
</Pie>
|
|
242
|
-
<Tooltip content={(props) => renderTooltip(getTooltipRow(props.payload), typeof props.label === 'string' ? props.label : undefined)} />
|
|
243
|
-
{showLegend && !isCompact && <Legend wrapperStyle={{ fontSize: 12 }} verticalAlign="bottom" />}
|
|
244
|
-
</PieChart>
|
|
245
|
-
</ResponsiveContainer>
|
|
246
|
-
</div>
|
|
247
|
-
</div>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Bar and Line charts
|
|
252
|
-
return (
|
|
253
|
-
<div ref={containerRef} className="w-full min-w-0 mt-4 mb-2 select-none overflow-hidden">
|
|
254
|
-
<div className="w-full aspect-[4/3]">
|
|
255
|
-
<ResponsiveContainer width="100%" height="100%">
|
|
256
|
-
{type === 'bar' ? (
|
|
257
|
-
<BarChart data={sanitizedData} margin={chartMargin}>
|
|
258
|
-
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
|
|
259
|
-
<XAxis dataKey={finalXKey} tick={axisTick} tickFormatter={truncateAxisLabel} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} interval={0} minTickGap={isTiny ? 2 : isCompact ? 6 : 12} />
|
|
260
|
-
<YAxis tick={axisTick} tickLine={false} axisLine={false} />
|
|
261
|
-
<Tooltip content={(props) => renderTooltip(getTooltipRow(props.payload), typeof props.label === 'string' ? props.label : undefined)} cursor={{ fill: '#f1f5f9' }} />
|
|
262
|
-
{showLegend && <Legend wrapperStyle={{ fontSize: isCompact ? 10 : 12 }} />}
|
|
263
|
-
{finalDataKeys.map((key, index) => (
|
|
264
|
-
<Bar
|
|
265
|
-
key={key}
|
|
266
|
-
dataKey={key}
|
|
267
|
-
fill={colors[index % colors.length]}
|
|
268
|
-
radius={[4, 4, 0, 0]}
|
|
269
|
-
barSize={isTiny ? Math.max(10, 28 / data.length) : isCompact ? Math.max(14, 42 / data.length) : Math.max(20, 60 / data.length)}
|
|
270
|
-
/>
|
|
271
|
-
))}
|
|
272
|
-
</BarChart>
|
|
273
|
-
) : (
|
|
274
|
-
<LineChart data={sanitizedData} margin={chartMargin}>
|
|
275
|
-
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
|
|
276
|
-
<XAxis dataKey={finalXKey} tick={axisTick} tickFormatter={truncateAxisLabel} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} interval={0} minTickGap={isTiny ? 2 : isCompact ? 6 : 12} />
|
|
277
|
-
<YAxis tick={axisTick} tickLine={false} axisLine={false} />
|
|
278
|
-
<Tooltip content={(props) => renderTooltip(getTooltipRow(props.payload), typeof props.label === 'string' ? props.label : undefined)} />
|
|
279
|
-
{showLegend && <Legend wrapperStyle={{ fontSize: isCompact ? 10 : 12 }} />}
|
|
280
|
-
{finalDataKeys.map((key, index) => (
|
|
281
|
-
<Line
|
|
282
|
-
key={key}
|
|
283
|
-
type="monotone"
|
|
284
|
-
dataKey={key}
|
|
285
|
-
stroke={colors[index % colors.length]}
|
|
286
|
-
strokeWidth={isTiny ? 1.75 : isCompact ? 2 : 3}
|
|
287
|
-
dot={{ r: isTiny ? 2.5 : isCompact ? 3 : 4, strokeWidth: 2 }}
|
|
288
|
-
activeDot={{ r: isTiny ? 4 : isCompact ? 5 : 6 }}
|
|
289
|
-
/>
|
|
290
|
-
))}
|
|
291
|
-
</LineChart>
|
|
292
|
-
)}
|
|
293
|
-
</ResponsiveContainer>
|
|
294
|
-
</div>
|
|
295
|
-
</div>
|
|
296
|
-
);
|
|
297
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
interface HourglassLoaderProps {
|
|
4
|
-
size?: number;
|
|
5
|
-
primaryColor?: string;
|
|
6
|
-
accentColor?: string;
|
|
7
|
-
glow?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const HourglassLoader: React.FC<HourglassLoaderProps> = ({
|
|
11
|
-
size = 16,
|
|
12
|
-
primaryColor = '#10b981',
|
|
13
|
-
glow = false,
|
|
14
|
-
}) => {
|
|
15
|
-
return (
|
|
16
|
-
<svg
|
|
17
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
18
|
-
viewBox="0 0 100 100"
|
|
19
|
-
preserveAspectRatio="xMidYMid"
|
|
20
|
-
style={{
|
|
21
|
-
width: size,
|
|
22
|
-
height: size,
|
|
23
|
-
background: 'transparent',
|
|
24
|
-
filter: glow ? `drop-shadow(0 0 4px ${primaryColor})` : 'none',
|
|
25
|
-
}}
|
|
26
|
-
>
|
|
27
|
-
<g>
|
|
28
|
-
{/* Rotation Animation */}
|
|
29
|
-
<animateTransform
|
|
30
|
-
attributeName="transform"
|
|
31
|
-
type="rotate"
|
|
32
|
-
calcMode="spline"
|
|
33
|
-
values="0 50 50; 0 50 50; 180 50 50"
|
|
34
|
-
keyTimes="0; 0.8; 1"
|
|
35
|
-
keySplines="0 0 1 1; 0.4 0 0.2 1"
|
|
36
|
-
dur="2s"
|
|
37
|
-
repeatCount="indefinite"
|
|
38
|
-
/>
|
|
39
|
-
|
|
40
|
-
{/* Glass Outline */}
|
|
41
|
-
<path
|
|
42
|
-
d="M 25 15 L 75 15 L 75 20 L 55 50 L 75 80 L 75 85 L 25 85 L 25 80 L 45 50 L 25 20 Z"
|
|
43
|
-
fill="none"
|
|
44
|
-
stroke={primaryColor}
|
|
45
|
-
strokeWidth="5"
|
|
46
|
-
strokeLinejoin="round"
|
|
47
|
-
strokeLinecap="round"
|
|
48
|
-
/>
|
|
49
|
-
|
|
50
|
-
{/* Top Sand */}
|
|
51
|
-
<path fill={primaryColor}>
|
|
52
|
-
<animate
|
|
53
|
-
attributeName="d"
|
|
54
|
-
values="M 30 20 L 70 20 L 50 50 L 50 50 Z; M 50 50 L 50 50 L 50 50 L 50 50 Z; M 50 50 L 50 50 L 50 50 L 50 50 Z"
|
|
55
|
-
keyTimes="0; 0.8; 1"
|
|
56
|
-
dur="2s"
|
|
57
|
-
repeatCount="indefinite"
|
|
58
|
-
/>
|
|
59
|
-
</path>
|
|
60
|
-
|
|
61
|
-
{/* Bottom Sand */}
|
|
62
|
-
<path fill={primaryColor}>
|
|
63
|
-
<animate
|
|
64
|
-
attributeName="d"
|
|
65
|
-
values="M 30 80 L 70 80 L 70 80 L 30 80 Z; M 30 80 L 70 80 L 50 50 L 50 50 Z; M 30 80 L 70 80 L 50 50 L 50 50 Z"
|
|
66
|
-
keyTimes="0; 0.8; 1"
|
|
67
|
-
dur="2s"
|
|
68
|
-
repeatCount="indefinite"
|
|
69
|
-
/>
|
|
70
|
-
</path>
|
|
71
|
-
|
|
72
|
-
{/* Falling Sand Stream */}
|
|
73
|
-
<line x1="50" y1="50" x2="50" y2="80" stroke={primaryColor} strokeWidth="3">
|
|
74
|
-
<animate
|
|
75
|
-
attributeName="opacity"
|
|
76
|
-
values="0; 1; 1; 0; 0"
|
|
77
|
-
keyTimes="0; 0.1; 0.7; 0.8; 1"
|
|
78
|
-
dur="2s"
|
|
79
|
-
repeatCount="indefinite"
|
|
80
|
-
/>
|
|
81
|
-
</line>
|
|
82
|
-
</g>
|
|
83
|
-
</svg>
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export default HourglassLoader;
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Components } from 'react-markdown';
|
|
3
|
-
import { UIDispatcher } from './UIDispatcher';
|
|
4
|
-
import { Product } from '../types';
|
|
5
|
-
import { ChatViewportSize } from '../types/props';
|
|
6
|
-
|
|
7
|
-
interface MarkdownComponentsProps {
|
|
8
|
-
primaryColor: string;
|
|
9
|
-
accentColor: string;
|
|
10
|
-
isStreaming: boolean;
|
|
11
|
-
onAddToCart?: (product: Product) => void;
|
|
12
|
-
viewportSize: ChatViewportSize;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createMarkdownComponents({
|
|
16
|
-
primaryColor,
|
|
17
|
-
accentColor,
|
|
18
|
-
isStreaming,
|
|
19
|
-
onAddToCart,
|
|
20
|
-
viewportSize,
|
|
21
|
-
}: MarkdownComponentsProps): Components {
|
|
22
|
-
return {
|
|
23
|
-
// p: ({ ...props }: React.HTMLAttributes<HTMLParagraphElement>) => (
|
|
24
|
-
// <p className="whitespace-pre-line" {...props} />
|
|
25
|
-
// ),
|
|
26
|
-
table: ({ ...props }: React.HTMLAttributes<HTMLTableElement>) => {
|
|
27
|
-
// Fix: intercept table rendering during streaming instead of using sentinel
|
|
28
|
-
if (isStreaming) {
|
|
29
|
-
return (
|
|
30
|
-
<div className="my-5 p-6 bg-slate-50 dark:bg-white/5 rounded-xl border border-dashed border-slate-300 dark:border-white/10 flex items-center justify-center gap-3 select-none">
|
|
31
|
-
<div className="w-4 h-4 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin" />
|
|
32
|
-
<p className="text-xs text-slate-500 font-medium italic animate-pulse">
|
|
33
|
-
Generating data table...
|
|
34
|
-
</p>
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div className="not-prose overflow-hidden my-5 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm bg-white dark:bg-slate-900/50">
|
|
41
|
-
<div className="overflow-x-auto">
|
|
42
|
-
<table
|
|
43
|
-
className="!table w-full text-left border-collapse min-w-[400px] text-sm"
|
|
44
|
-
{...props}
|
|
45
|
-
/>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
},
|
|
50
|
-
thead: ({ ...props }: React.HTMLAttributes<HTMLTableSectionElement>) => (
|
|
51
|
-
<thead
|
|
52
|
-
className="!table-header-group bg-slate-50 dark:bg-white/5 border-b border-slate-200 dark:border-white/10"
|
|
53
|
-
{...props}
|
|
54
|
-
/>
|
|
55
|
-
),
|
|
56
|
-
tbody: ({ ...props }: React.HTMLAttributes<HTMLTableSectionElement>) => (
|
|
57
|
-
<tbody className="!table-row-group divide-y divide-slate-100 dark:divide-white/5" {...props} />
|
|
58
|
-
),
|
|
59
|
-
tr: ({ ...props }: React.HTMLAttributes<HTMLTableRowElement>) => (
|
|
60
|
-
<tr
|
|
61
|
-
className="!table-row hover:bg-slate-50/70 dark:hover:bg-white/5 transition-colors"
|
|
62
|
-
{...props}
|
|
63
|
-
/>
|
|
64
|
-
),
|
|
65
|
-
th: ({ children, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) => (
|
|
66
|
-
<th
|
|
67
|
-
className="!table-cell px-4 py-3 font-bold text-slate-700 dark:text-white/90 whitespace-nowrap text-[11px] uppercase tracking-wider text-left"
|
|
68
|
-
{...props}
|
|
69
|
-
>
|
|
70
|
-
{normaliseChild(children)}
|
|
71
|
-
</th>
|
|
72
|
-
),
|
|
73
|
-
td: ({ children, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) => (
|
|
74
|
-
<td
|
|
75
|
-
className="!table-cell px-4 py-3 text-slate-600 dark:text-white/70 whitespace-nowrap text-sm"
|
|
76
|
-
{...props}
|
|
77
|
-
>
|
|
78
|
-
{normaliseChild(children)}
|
|
79
|
-
</td>
|
|
80
|
-
),
|
|
81
|
-
code({
|
|
82
|
-
inline,
|
|
83
|
-
className,
|
|
84
|
-
children,
|
|
85
|
-
...props
|
|
86
|
-
}: React.HTMLAttributes<HTMLElement> & { inline?: boolean }) {
|
|
87
|
-
const lang = /language-(\w+)/.exec(className ?? '')?.[1];
|
|
88
|
-
|
|
89
|
-
if (!inline && (lang === 'ui' || lang === 'chart' || lang === 'json')) {
|
|
90
|
-
const content = String(children ?? '').trim();
|
|
91
|
-
// Since we extract pure components, UIDispatcher handles these formats
|
|
92
|
-
return (
|
|
93
|
-
<UIDispatcher
|
|
94
|
-
rawContent={content}
|
|
95
|
-
primaryColor={primaryColor}
|
|
96
|
-
accentColor={accentColor}
|
|
97
|
-
isStreaming={isStreaming}
|
|
98
|
-
onAddToCart={onAddToCart}
|
|
99
|
-
viewportSize={viewportSize}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!inline) {
|
|
105
|
-
const content = String(children ?? '').trim();
|
|
106
|
-
// Fallback catch for json payload without lang block
|
|
107
|
-
if (content.startsWith('{') && content.endsWith('}')) {
|
|
108
|
-
return (
|
|
109
|
-
<UIDispatcher
|
|
110
|
-
rawContent={content}
|
|
111
|
-
primaryColor={primaryColor}
|
|
112
|
-
accentColor={accentColor}
|
|
113
|
-
isStreaming={isStreaming}
|
|
114
|
-
onAddToCart={onAddToCart}
|
|
115
|
-
viewportSize={viewportSize}
|
|
116
|
-
/>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
return <CodeBlock language={lang}>{content}</CodeBlock>;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<code className="px-1.5 py-0.5 rounded bg-slate-100 dark:bg-white/10 text-rose-600 dark:text-rose-400 font-mono text-[11px]" {...props}>
|
|
124
|
-
{typeof children === 'string' || typeof children === 'number'
|
|
125
|
-
? children
|
|
126
|
-
: JSON.stringify(children)}
|
|
127
|
-
</code>
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function CodeBlock({ children, language }: { children: string; language?: string }) {
|
|
134
|
-
const [copied, setCopied] = React.useState(false);
|
|
135
|
-
|
|
136
|
-
const handleCopy = async () => {
|
|
137
|
-
try {
|
|
138
|
-
await navigator.clipboard.writeText(children);
|
|
139
|
-
setCopied(true);
|
|
140
|
-
setTimeout(() => setCopied(false), 2000);
|
|
141
|
-
} catch (e) {
|
|
142
|
-
console.warn('Failed to copy code', e);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<div className="not-prose my-4 rounded-xl border border-slate-200 dark:border-white/10 overflow-hidden bg-slate-900 text-slate-100 shadow-lg select-text">
|
|
148
|
-
<div className="flex items-center justify-between px-4 py-2 bg-slate-950 border-b border-slate-800 text-xs font-semibold text-slate-400 select-none">
|
|
149
|
-
<span className="font-mono lowercase">{language || 'code'}</span>
|
|
150
|
-
<button
|
|
151
|
-
onClick={handleCopy}
|
|
152
|
-
className="flex items-center gap-1.5 px-2 py-1 rounded hover:bg-slate-800 hover:text-slate-250 transition-colors cursor-pointer text-slate-400 border border-transparent hover:border-slate-800"
|
|
153
|
-
type="button"
|
|
154
|
-
>
|
|
155
|
-
{copied ? (
|
|
156
|
-
<>
|
|
157
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" className="text-emerald-500"><polyline points="20 6 9 17 4 12"/></svg>
|
|
158
|
-
<span className="text-emerald-500">Copied!</span>
|
|
159
|
-
</>
|
|
160
|
-
) : (
|
|
161
|
-
<>
|
|
162
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
163
|
-
<span>Copy</span>
|
|
164
|
-
</>
|
|
165
|
-
)}
|
|
166
|
-
</button>
|
|
167
|
-
</div>
|
|
168
|
-
<div className="p-4 overflow-x-auto font-mono text-[11px] leading-relaxed text-slate-200 bg-slate-900/90 whitespace-pre">
|
|
169
|
-
<code>{children}</code>
|
|
170
|
-
</div>
|
|
171
|
-
</div>
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Safely render table cell children that might be plain objects. */
|
|
176
|
-
function normaliseChild(children: unknown): React.ReactNode {
|
|
177
|
-
if (
|
|
178
|
-
typeof children === 'object' &&
|
|
179
|
-
children !== null &&
|
|
180
|
-
!Array.isArray(children) &&
|
|
181
|
-
!React.isValidElement(children)
|
|
182
|
-
) {
|
|
183
|
-
return JSON.stringify(children);
|
|
184
|
-
}
|
|
185
|
-
return children as React.ReactNode;
|
|
186
|
-
}
|