@retrivora-ai/rag-engine 1.4.7 → 1.4.8
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/dist/index.js +14 -3
- package/dist/index.mjs +14 -3
- package/package.json +1 -1
- package/src/components/DynamicChart.tsx +15 -5
- package/src/components/MessageBubble.tsx +5 -0
package/dist/index.js
CHANGED
|
@@ -235,13 +235,21 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
235
235
|
Object.keys(subItem).forEach((sk) => {
|
|
236
236
|
const subVal = subItem[sk];
|
|
237
237
|
if (typeof subVal !== "object" || subVal === null) {
|
|
238
|
-
|
|
238
|
+
if (typeof subVal === "string" && !isNaN(Number(subVal)) && subVal.trim() !== "") {
|
|
239
|
+
newItem[sk] = Number(subVal);
|
|
240
|
+
} else {
|
|
241
|
+
newItem[sk] = subVal;
|
|
242
|
+
}
|
|
239
243
|
}
|
|
240
244
|
});
|
|
241
245
|
}
|
|
242
246
|
});
|
|
243
247
|
} else if (typeof val !== "object" || val === null) {
|
|
244
|
-
|
|
248
|
+
if (typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
|
|
249
|
+
newItem[k] = Number(val);
|
|
250
|
+
} else {
|
|
251
|
+
newItem[k] = val;
|
|
252
|
+
}
|
|
245
253
|
}
|
|
246
254
|
});
|
|
247
255
|
return newItem;
|
|
@@ -250,7 +258,7 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
250
258
|
if (!data || data.length === 0) {
|
|
251
259
|
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "p-4 text-sm text-slate-500" }, "No data available for chart.");
|
|
252
260
|
}
|
|
253
|
-
const firstItem =
|
|
261
|
+
const firstItem = sanitizedData[0];
|
|
254
262
|
const allKeys = Object.keys(firstItem);
|
|
255
263
|
const resolvedXKey = config.xAxisKey && firstItem[config.xAxisKey] !== void 0 ? config.xAxisKey : allKeys.find((k) => k.toLowerCase() === "name" || k.toLowerCase() === "label" || k.toLowerCase() === "category") || allKeys.find((k) => typeof firstItem[k] === "string") || allKeys[0];
|
|
256
264
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
|
|
@@ -497,6 +505,9 @@ function MessageBubble({
|
|
|
497
505
|
}, [sources, isUser]);
|
|
498
506
|
const { productsFromContent, cleanContent } = import_react5.default.useMemo(() => {
|
|
499
507
|
if (isUser) return { productsFromContent: [], cleanContent: message.content };
|
|
508
|
+
if (message.content.includes("```chart")) {
|
|
509
|
+
return { productsFromContent: [], cleanContent: message.content };
|
|
510
|
+
}
|
|
500
511
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
501
512
|
const products = [];
|
|
502
513
|
let content = message.content;
|
package/dist/index.mjs
CHANGED
|
@@ -198,13 +198,21 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
198
198
|
Object.keys(subItem).forEach((sk) => {
|
|
199
199
|
const subVal = subItem[sk];
|
|
200
200
|
if (typeof subVal !== "object" || subVal === null) {
|
|
201
|
-
|
|
201
|
+
if (typeof subVal === "string" && !isNaN(Number(subVal)) && subVal.trim() !== "") {
|
|
202
|
+
newItem[sk] = Number(subVal);
|
|
203
|
+
} else {
|
|
204
|
+
newItem[sk] = subVal;
|
|
205
|
+
}
|
|
202
206
|
}
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
});
|
|
206
210
|
} else if (typeof val !== "object" || val === null) {
|
|
207
|
-
|
|
211
|
+
if (typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
|
|
212
|
+
newItem[k] = Number(val);
|
|
213
|
+
} else {
|
|
214
|
+
newItem[k] = val;
|
|
215
|
+
}
|
|
208
216
|
}
|
|
209
217
|
});
|
|
210
218
|
return newItem;
|
|
@@ -213,7 +221,7 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
213
221
|
if (!data || data.length === 0) {
|
|
214
222
|
return /* @__PURE__ */ React4.createElement("div", { className: "p-4 text-sm text-slate-500" }, "No data available for chart.");
|
|
215
223
|
}
|
|
216
|
-
const firstItem =
|
|
224
|
+
const firstItem = sanitizedData[0];
|
|
217
225
|
const allKeys = Object.keys(firstItem);
|
|
218
226
|
const resolvedXKey = config.xAxisKey && firstItem[config.xAxisKey] !== void 0 ? config.xAxisKey : allKeys.find((k) => k.toLowerCase() === "name" || k.toLowerCase() === "label" || k.toLowerCase() === "category") || allKeys.find((k) => typeof firstItem[k] === "string") || allKeys[0];
|
|
219
227
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
|
|
@@ -460,6 +468,9 @@ function MessageBubble({
|
|
|
460
468
|
}, [sources, isUser]);
|
|
461
469
|
const { productsFromContent, cleanContent } = React5.useMemo(() => {
|
|
462
470
|
if (isUser) return { productsFromContent: [], cleanContent: message.content };
|
|
471
|
+
if (message.content.includes("```chart")) {
|
|
472
|
+
return { productsFromContent: [], cleanContent: message.content };
|
|
473
|
+
}
|
|
463
474
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
464
475
|
const products = [];
|
|
465
476
|
let content = message.content;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.8",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,6 +29,8 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
29
29
|
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
30
30
|
// This prevents the "Objects are not valid as a React child" error in Tooltips/Legends
|
|
31
31
|
// This hook MUST be called before any early returns to satisfy React rules
|
|
32
|
+
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
33
|
+
// Also ensures numeric strings are converted to actual numbers for Recharts.
|
|
32
34
|
const sanitizedData = React.useMemo(() => {
|
|
33
35
|
if (!data) return [];
|
|
34
36
|
return data.map(item => {
|
|
@@ -36,19 +38,28 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
36
38
|
Object.keys(item).forEach(k => {
|
|
37
39
|
const val = item[k];
|
|
38
40
|
if (Array.isArray(val)) {
|
|
39
|
-
// If the LLM output nested arrays, attempt to flatten them
|
|
40
41
|
val.forEach(subItem => {
|
|
41
42
|
if (typeof subItem === 'object' && subItem !== null) {
|
|
42
43
|
Object.keys(subItem).forEach(sk => {
|
|
43
44
|
const subVal = (subItem as Record<string, unknown>)[sk];
|
|
44
45
|
if (typeof subVal !== 'object' || subVal === null) {
|
|
45
|
-
|
|
46
|
+
// Auto-convert numeric strings
|
|
47
|
+
if (typeof subVal === 'string' && !isNaN(Number(subVal)) && subVal.trim() !== '') {
|
|
48
|
+
newItem[sk] = Number(subVal);
|
|
49
|
+
} else {
|
|
50
|
+
newItem[sk] = subVal as string | number | null;
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
55
|
});
|
|
50
56
|
} else if (typeof val !== 'object' || val === null) {
|
|
51
|
-
|
|
57
|
+
// Auto-convert numeric strings
|
|
58
|
+
if (typeof val === 'string' && !isNaN(Number(val)) && val.trim() !== '') {
|
|
59
|
+
newItem[k] = Number(val);
|
|
60
|
+
} else {
|
|
61
|
+
newItem[k] = val as string | number | null;
|
|
62
|
+
}
|
|
52
63
|
}
|
|
53
64
|
});
|
|
54
65
|
return newItem;
|
|
@@ -60,7 +71,7 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
// Smart key resolution: if the provided keys don't exist in the data, try to guess them
|
|
63
|
-
const firstItem =
|
|
74
|
+
const firstItem = sanitizedData[0];
|
|
64
75
|
const allKeys = Object.keys(firstItem);
|
|
65
76
|
|
|
66
77
|
// Resolve xAxisKey: use provided, fallback to 'name', 'label', 'category', or the first string key
|
|
@@ -71,7 +82,6 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
71
82
|
|| allKeys[0];
|
|
72
83
|
|
|
73
84
|
// Resolve dataKeys: use provided, fallback to 'value', 'count', 'amount', or all numeric keys
|
|
74
|
-
// CRITICAL: Filter out any keys that point to objects/arrays to prevent React render errors
|
|
75
85
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every(k => {
|
|
76
86
|
const val = firstItem[k];
|
|
77
87
|
return val !== undefined && typeof val !== 'object';
|
|
@@ -313,6 +313,11 @@ export function MessageBubble({
|
|
|
313
313
|
const { productsFromContent, cleanContent } = React.useMemo(() => {
|
|
314
314
|
if (isUser) return { productsFromContent: [] as Product[], cleanContent: message.content };
|
|
315
315
|
|
|
316
|
+
// If the message contains a chart, suppress the product carousel to keep focus on visualization
|
|
317
|
+
if (message.content.includes('```chart')) {
|
|
318
|
+
return { productsFromContent: [] as Product[], cleanContent: message.content };
|
|
319
|
+
}
|
|
320
|
+
|
|
316
321
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
317
322
|
const products: Product[] = [];
|
|
318
323
|
let content = message.content;
|