@retrivora-ai/rag-engine 1.3.0 → 1.3.1

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 CHANGED
@@ -229,18 +229,35 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
229
229
  const firstItem = data[0];
230
230
  const allKeys = Object.keys(firstItem);
231
231
  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];
232
- const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => firstItem[k] !== void 0) ? config.dataKeys : allKeys.filter((k) => k !== resolvedXKey && (typeof firstItem[k] === "number" || k.toLowerCase() === "value" || k.toLowerCase() === "count")).slice(0, 5);
233
- if (resolvedDataKeys.length === 0 && allKeys.length > 1) {
234
- resolvedDataKeys.push(allKeys.find((k) => k !== resolvedXKey) || allKeys[1]);
235
- }
232
+ const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
233
+ const val = firstItem[k];
234
+ return val !== void 0 && typeof val !== "object";
235
+ }) ? config.dataKeys : allKeys.filter((k) => {
236
+ const val = firstItem[k];
237
+ return k !== resolvedXKey && (typeof val === "number" || k.toLowerCase() === "value" || k.toLowerCase() === "count");
238
+ }).slice(0, 5);
239
+ const finalXKey = String(resolvedXKey);
240
+ const finalDataKeys = resolvedDataKeys.map(String).filter((k) => k !== "undefined");
241
+ const sanitizedData = import_react4.default.useMemo(() => {
242
+ return data.map((item) => {
243
+ const newItem = {};
244
+ Object.keys(item).forEach((k) => {
245
+ const val = item[k];
246
+ if (typeof val !== "object" || val === null) {
247
+ newItem[k] = val;
248
+ }
249
+ });
250
+ return newItem;
251
+ });
252
+ }, [data]);
236
253
  if (type === "pie") {
237
- const pieDataKey = resolvedDataKeys[0] || "value";
254
+ const pieDataKey = finalDataKeys[0] || "value";
238
255
  return /* @__PURE__ */ import_react4.default.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.ResponsiveContainer, { width: "99%", height: "100%" }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.PieChart, null, /* @__PURE__ */ import_react4.default.createElement(
239
256
  import_recharts.Pie,
240
257
  {
241
- data,
258
+ data: sanitizedData,
242
259
  dataKey: pieDataKey,
243
- nameKey: resolvedXKey,
260
+ nameKey: finalXKey,
244
261
  cx: "50%",
245
262
  cy: "50%",
246
263
  outerRadius: 80,
@@ -254,13 +271,13 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
254
271
  }
255
272
  ), /* @__PURE__ */ import_react4.default.createElement(import_recharts.Legend, null))));
256
273
  }
257
- return /* @__PURE__ */ import_react4.default.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.ResponsiveContainer, { width: "99%", height: "100%" }, type === "bar" ? /* @__PURE__ */ import_react4.default.createElement(import_recharts.BarChart, { data, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.XAxis, { dataKey: resolvedXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ import_react4.default.createElement(
274
+ return /* @__PURE__ */ import_react4.default.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.ResponsiveContainer, { width: "99%", height: "100%" }, type === "bar" ? /* @__PURE__ */ import_react4.default.createElement(import_recharts.BarChart, { data: sanitizedData, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.XAxis, { dataKey: finalXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ import_react4.default.createElement(
258
275
  import_recharts.Tooltip,
259
276
  {
260
277
  contentStyle: { borderRadius: "8px", border: "none", boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)" },
261
278
  cursor: { fill: "#f1f5f9" }
262
279
  }
263
- ), /* @__PURE__ */ import_react4.default.createElement(import_recharts.Legend, { wrapperStyle: { fontSize: 12 } }), resolvedDataKeys.map((key, index) => /* @__PURE__ */ import_react4.default.createElement(
280
+ ), /* @__PURE__ */ import_react4.default.createElement(import_recharts.Legend, { wrapperStyle: { fontSize: 12 } }), finalDataKeys.map((key, index) => /* @__PURE__ */ import_react4.default.createElement(
264
281
  import_recharts.Bar,
265
282
  {
266
283
  key,
@@ -269,12 +286,12 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
269
286
  radius: [4, 4, 0, 0],
270
287
  barSize: Math.max(20, 60 / data.length)
271
288
  }
272
- ))) : /* @__PURE__ */ import_react4.default.createElement(import_recharts.LineChart, { data, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.XAxis, { dataKey: resolvedXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ import_react4.default.createElement(
289
+ ))) : /* @__PURE__ */ import_react4.default.createElement(import_recharts.LineChart, { data: sanitizedData, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ import_react4.default.createElement(import_recharts.CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.XAxis, { dataKey: finalXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ import_react4.default.createElement(import_recharts.YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ import_react4.default.createElement(
273
290
  import_recharts.Tooltip,
274
291
  {
275
292
  contentStyle: { borderRadius: "8px", border: "none", boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)" }
276
293
  }
277
- ), /* @__PURE__ */ import_react4.default.createElement(import_recharts.Legend, { wrapperStyle: { fontSize: 12 } }), resolvedDataKeys.map((key, index) => /* @__PURE__ */ import_react4.default.createElement(
294
+ ), /* @__PURE__ */ import_react4.default.createElement(import_recharts.Legend, { wrapperStyle: { fontSize: 12 } }), finalDataKeys.map((key, index) => /* @__PURE__ */ import_react4.default.createElement(
278
295
  import_recharts.Line,
279
296
  {
280
297
  key,
@@ -397,15 +414,15 @@ function MessageBubble({
397
414
  return /* @__PURE__ */ import_react5.default.createElement("thead", __spreadValues({ className: "bg-slate-50 dark:bg-white/5 border-b border-slate-200 dark:border-white/10" }, props));
398
415
  },
399
416
  th: (_c) => {
400
- var props = __objRest(_c, []);
401
- return /* @__PURE__ */ import_react5.default.createElement("th", __spreadValues({ className: "p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" }, props));
417
+ var _d = _c, { children } = _d, props = __objRest(_d, ["children"]);
418
+ return /* @__PURE__ */ import_react5.default.createElement("th", __spreadValues({ className: "p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" }, props), typeof children === "object" && children !== null && !Array.isArray(children) && !children.$$typeof ? JSON.stringify(children) : children);
402
419
  },
403
- td: (_d) => {
404
- var props = __objRest(_d, []);
405
- return /* @__PURE__ */ import_react5.default.createElement("td", __spreadValues({ className: "p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" }, props));
420
+ td: (_e) => {
421
+ var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
422
+ return /* @__PURE__ */ import_react5.default.createElement("td", __spreadValues({ className: "p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" }, props), typeof children === "object" && children !== null && !Array.isArray(children) && !children.$$typeof ? JSON.stringify(children) : children);
406
423
  },
407
- code(_e) {
408
- var _f = _e, { inline, className, children } = _f, props = __objRest(_f, ["inline", "className", "children"]);
424
+ code(_g) {
425
+ var _h = _g, { inline, className, children } = _h, props = __objRest(_h, ["inline", "className", "children"]);
409
426
  const match = /language-(\w+)/.exec(className || "");
410
427
  const isChart = match && match[1] === "chart";
411
428
  if (!inline && isChart) {
@@ -415,15 +432,12 @@ function MessageBubble({
415
432
  }
416
433
  const sanitizeJson = (json) => {
417
434
  return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
435
+ var _a;
418
436
  const v1 = parseFloat(n1);
419
437
  const v2 = parseFloat(n2);
420
- let res = v1;
421
- if (op === "+") res = v1 + v2;
422
- if (op === "-") res = v1 - v2;
423
- if (op === "*") res = v1 * v2;
424
- if (op === "/") res = v1 / v2;
425
- return `: ${res}`;
426
- }).replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"').replace(/,\s*([\]}])/g, "$1").replace(/}\s*{/g, "},{").replace(/]\s*\[/g, "],[").replace(/\/\/.*$/gm, "").replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
438
+ const ops = { "+": v1 + v2, "-": v1 - v2, "*": v1 * v2, "/": v1 / v2 };
439
+ return `: ${(_a = ops[op]) != null ? _a : v1}`;
440
+ }).replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"').replace(/,\s*([\]}])/g, "$1").replace(/}\s*{/g, "},{").replace(/]\s*\[/g, "],[").replace(/\/\/.*$/gm, "").replace(/([{,])\s*""\s*([,}])/g, "$1$2");
427
441
  };
428
442
  try {
429
443
  const sanitized = sanitizeJson(rawContent);
@@ -441,7 +455,7 @@ function MessageBubble({
441
455
  return /* @__PURE__ */ import_react5.default.createElement("div", { className: "p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-lg text-sm border border-red-100 dark:border-red-900/30" }, /* @__PURE__ */ import_react5.default.createElement("p", { className: "font-medium mb-1" }, "Failed to render chart"), /* @__PURE__ */ import_react5.default.createElement("p", { className: "opacity-70 text-xs" }, "The generated configuration is invalid. Check console for details."));
442
456
  }
443
457
  }
444
- return /* @__PURE__ */ import_react5.default.createElement("code", __spreadValues({ className }, props), children);
458
+ return /* @__PURE__ */ import_react5.default.createElement("code", __spreadValues({ className }, props), typeof children === "string" || typeof children === "number" ? children : JSON.stringify(children));
445
459
  }
446
460
  }
447
461
  },
package/dist/index.mjs CHANGED
@@ -192,18 +192,35 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
192
192
  const firstItem = data[0];
193
193
  const allKeys = Object.keys(firstItem);
194
194
  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];
195
- const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => firstItem[k] !== void 0) ? config.dataKeys : allKeys.filter((k) => k !== resolvedXKey && (typeof firstItem[k] === "number" || k.toLowerCase() === "value" || k.toLowerCase() === "count")).slice(0, 5);
196
- if (resolvedDataKeys.length === 0 && allKeys.length > 1) {
197
- resolvedDataKeys.push(allKeys.find((k) => k !== resolvedXKey) || allKeys[1]);
198
- }
195
+ const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
196
+ const val = firstItem[k];
197
+ return val !== void 0 && typeof val !== "object";
198
+ }) ? config.dataKeys : allKeys.filter((k) => {
199
+ const val = firstItem[k];
200
+ return k !== resolvedXKey && (typeof val === "number" || k.toLowerCase() === "value" || k.toLowerCase() === "count");
201
+ }).slice(0, 5);
202
+ const finalXKey = String(resolvedXKey);
203
+ const finalDataKeys = resolvedDataKeys.map(String).filter((k) => k !== "undefined");
204
+ const sanitizedData = React4.useMemo(() => {
205
+ return data.map((item) => {
206
+ const newItem = {};
207
+ Object.keys(item).forEach((k) => {
208
+ const val = item[k];
209
+ if (typeof val !== "object" || val === null) {
210
+ newItem[k] = val;
211
+ }
212
+ });
213
+ return newItem;
214
+ });
215
+ }, [data]);
199
216
  if (type === "pie") {
200
- const pieDataKey = resolvedDataKeys[0] || "value";
217
+ const pieDataKey = finalDataKeys[0] || "value";
201
218
  return /* @__PURE__ */ React4.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ React4.createElement(ResponsiveContainer, { width: "99%", height: "100%" }, /* @__PURE__ */ React4.createElement(PieChart, null, /* @__PURE__ */ React4.createElement(
202
219
  Pie,
203
220
  {
204
- data,
221
+ data: sanitizedData,
205
222
  dataKey: pieDataKey,
206
- nameKey: resolvedXKey,
223
+ nameKey: finalXKey,
207
224
  cx: "50%",
208
225
  cy: "50%",
209
226
  outerRadius: 80,
@@ -217,13 +234,13 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
217
234
  }
218
235
  ), /* @__PURE__ */ React4.createElement(Legend, null))));
219
236
  }
220
- return /* @__PURE__ */ React4.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ React4.createElement(ResponsiveContainer, { width: "99%", height: "100%" }, type === "bar" ? /* @__PURE__ */ React4.createElement(BarChart, { data, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ React4.createElement(CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ React4.createElement(XAxis, { dataKey: resolvedXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ React4.createElement(YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ React4.createElement(
237
+ return /* @__PURE__ */ React4.createElement("div", { className: "w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden" }, /* @__PURE__ */ React4.createElement(ResponsiveContainer, { width: "99%", height: "100%" }, type === "bar" ? /* @__PURE__ */ React4.createElement(BarChart, { data: sanitizedData, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ React4.createElement(CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ React4.createElement(XAxis, { dataKey: finalXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ React4.createElement(YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ React4.createElement(
221
238
  Tooltip,
222
239
  {
223
240
  contentStyle: { borderRadius: "8px", border: "none", boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)" },
224
241
  cursor: { fill: "#f1f5f9" }
225
242
  }
226
- ), /* @__PURE__ */ React4.createElement(Legend, { wrapperStyle: { fontSize: 12 } }), resolvedDataKeys.map((key, index) => /* @__PURE__ */ React4.createElement(
243
+ ), /* @__PURE__ */ React4.createElement(Legend, { wrapperStyle: { fontSize: 12 } }), finalDataKeys.map((key, index) => /* @__PURE__ */ React4.createElement(
227
244
  Bar,
228
245
  {
229
246
  key,
@@ -232,12 +249,12 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
232
249
  radius: [4, 4, 0, 0],
233
250
  barSize: Math.max(20, 60 / data.length)
234
251
  }
235
- ))) : /* @__PURE__ */ React4.createElement(LineChart, { data, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ React4.createElement(CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ React4.createElement(XAxis, { dataKey: resolvedXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ React4.createElement(YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ React4.createElement(
252
+ ))) : /* @__PURE__ */ React4.createElement(LineChart, { data: sanitizedData, margin: { top: 10, right: 10, left: -20, bottom: 0 } }, /* @__PURE__ */ React4.createElement(CartesianGrid, { strokeDasharray: "3 3", vertical: false, stroke: "#e2e8f0" }), /* @__PURE__ */ React4.createElement(XAxis, { dataKey: finalXKey, tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: { stroke: "#cbd5e1" } }), /* @__PURE__ */ React4.createElement(YAxis, { tick: { fontSize: 12, fill: "#64748b" }, tickLine: false, axisLine: false }), /* @__PURE__ */ React4.createElement(
236
253
  Tooltip,
237
254
  {
238
255
  contentStyle: { borderRadius: "8px", border: "none", boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)" }
239
256
  }
240
- ), /* @__PURE__ */ React4.createElement(Legend, { wrapperStyle: { fontSize: 12 } }), resolvedDataKeys.map((key, index) => /* @__PURE__ */ React4.createElement(
257
+ ), /* @__PURE__ */ React4.createElement(Legend, { wrapperStyle: { fontSize: 12 } }), finalDataKeys.map((key, index) => /* @__PURE__ */ React4.createElement(
241
258
  Line,
242
259
  {
243
260
  key,
@@ -360,15 +377,15 @@ function MessageBubble({
360
377
  return /* @__PURE__ */ React5.createElement("thead", __spreadValues({ className: "bg-slate-50 dark:bg-white/5 border-b border-slate-200 dark:border-white/10" }, props));
361
378
  },
362
379
  th: (_c) => {
363
- var props = __objRest(_c, []);
364
- return /* @__PURE__ */ React5.createElement("th", __spreadValues({ className: "p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" }, props));
380
+ var _d = _c, { children } = _d, props = __objRest(_d, ["children"]);
381
+ return /* @__PURE__ */ React5.createElement("th", __spreadValues({ className: "p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" }, props), typeof children === "object" && children !== null && !Array.isArray(children) && !children.$$typeof ? JSON.stringify(children) : children);
365
382
  },
366
- td: (_d) => {
367
- var props = __objRest(_d, []);
368
- return /* @__PURE__ */ React5.createElement("td", __spreadValues({ className: "p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" }, props));
383
+ td: (_e) => {
384
+ var _f = _e, { children } = _f, props = __objRest(_f, ["children"]);
385
+ return /* @__PURE__ */ React5.createElement("td", __spreadValues({ className: "p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" }, props), typeof children === "object" && children !== null && !Array.isArray(children) && !children.$$typeof ? JSON.stringify(children) : children);
369
386
  },
370
- code(_e) {
371
- var _f = _e, { inline, className, children } = _f, props = __objRest(_f, ["inline", "className", "children"]);
387
+ code(_g) {
388
+ var _h = _g, { inline, className, children } = _h, props = __objRest(_h, ["inline", "className", "children"]);
372
389
  const match = /language-(\w+)/.exec(className || "");
373
390
  const isChart = match && match[1] === "chart";
374
391
  if (!inline && isChart) {
@@ -378,15 +395,12 @@ function MessageBubble({
378
395
  }
379
396
  const sanitizeJson = (json) => {
380
397
  return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
398
+ var _a;
381
399
  const v1 = parseFloat(n1);
382
400
  const v2 = parseFloat(n2);
383
- let res = v1;
384
- if (op === "+") res = v1 + v2;
385
- if (op === "-") res = v1 - v2;
386
- if (op === "*") res = v1 * v2;
387
- if (op === "/") res = v1 / v2;
388
- return `: ${res}`;
389
- }).replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"').replace(/,\s*([\]}])/g, "$1").replace(/}\s*{/g, "},{").replace(/]\s*\[/g, "],[").replace(/\/\/.*$/gm, "").replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
401
+ const ops = { "+": v1 + v2, "-": v1 - v2, "*": v1 * v2, "/": v1 / v2 };
402
+ return `: ${(_a = ops[op]) != null ? _a : v1}`;
403
+ }).replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"').replace(/,\s*([\]}])/g, "$1").replace(/}\s*{/g, "},{").replace(/]\s*\[/g, "],[").replace(/\/\/.*$/gm, "").replace(/([{,])\s*""\s*([,}])/g, "$1$2");
390
404
  };
391
405
  try {
392
406
  const sanitized = sanitizeJson(rawContent);
@@ -404,7 +418,7 @@ function MessageBubble({
404
418
  return /* @__PURE__ */ React5.createElement("div", { className: "p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-lg text-sm border border-red-100 dark:border-red-900/30" }, /* @__PURE__ */ React5.createElement("p", { className: "font-medium mb-1" }, "Failed to render chart"), /* @__PURE__ */ React5.createElement("p", { className: "opacity-70 text-xs" }, "The generated configuration is invalid. Check console for details."));
405
419
  }
406
420
  }
407
- return /* @__PURE__ */ React5.createElement("code", __spreadValues({ className }, props), children);
421
+ return /* @__PURE__ */ React5.createElement("code", __spreadValues({ className }, props), typeof children === "string" || typeof children === "number" ? children : JSON.stringify(children));
408
422
  }
409
423
  }
410
424
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",
@@ -42,28 +42,49 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
42
42
  || allKeys[0];
43
43
 
44
44
  // Resolve dataKeys: use provided, fallback to 'value', 'count', 'amount', or all numeric keys
45
- const resolvedDataKeys = config.dataKeys && config.dataKeys.every(k => firstItem[k] !== undefined)
45
+ // CRITICAL: Filter out any keys that point to objects/arrays to prevent React render errors
46
+ const resolvedDataKeys = config.dataKeys && config.dataKeys.every(k => {
47
+ const val = firstItem[k];
48
+ return val !== undefined && typeof val !== 'object';
49
+ })
46
50
  ? config.dataKeys
47
- : allKeys.filter(k => k !== resolvedXKey && (typeof firstItem[k] === 'number' || k.toLowerCase() === 'value' || k.toLowerCase() === 'count'))
51
+ : allKeys.filter(k => {
52
+ const val = firstItem[k];
53
+ return k !== resolvedXKey && (typeof val === 'number' || k.toLowerCase() === 'value' || k.toLowerCase() === 'count');
54
+ })
48
55
  .slice(0, 5); // Limit to 5 series for sanity
49
56
 
50
- if (resolvedDataKeys.length === 0 && allKeys.length > 1) {
51
- // Last resort: just use the second key
52
- resolvedDataKeys.push(allKeys.find(k => k !== resolvedXKey) || allKeys[1]);
53
- }
57
+ // Final sanity check: ensure all keys are strings
58
+ const finalXKey = String(resolvedXKey);
59
+ const finalDataKeys = resolvedDataKeys.map(String).filter(k => k !== 'undefined');
60
+
61
+ // CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
62
+ // This prevents the "Objects are not valid as a React child" error in Tooltips/Legends
63
+ const sanitizedData = React.useMemo(() => {
64
+ return data.map(item => {
65
+ const newItem: Record<string, any> = {};
66
+ Object.keys(item).forEach(k => {
67
+ const val = item[k];
68
+ if (typeof val !== 'object' || val === null) {
69
+ newItem[k] = val;
70
+ }
71
+ });
72
+ return newItem;
73
+ });
74
+ }, [data]);
54
75
 
55
76
  // Handle Pie Chart separately as it has a different structure
56
77
  if (type === 'pie') {
57
- const pieDataKey = resolvedDataKeys[0] || 'value';
78
+ const pieDataKey = finalDataKeys[0] || 'value';
58
79
 
59
80
  return (
60
81
  <div className="w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden">
61
82
  <ResponsiveContainer width="99%" height="100%">
62
83
  <PieChart>
63
84
  <Pie
64
- data={data}
85
+ data={sanitizedData}
65
86
  dataKey={pieDataKey}
66
- nameKey={resolvedXKey}
87
+ nameKey={finalXKey}
67
88
  cx="50%"
68
89
  cy="50%"
69
90
  outerRadius={80}
@@ -88,16 +109,16 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
88
109
  <div className="w-full h-72 min-h-[280px] mt-4 mb-2 select-none overflow-hidden">
89
110
  <ResponsiveContainer width="99%" height="100%">
90
111
  {type === 'bar' ? (
91
- <BarChart data={data} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
112
+ <BarChart data={sanitizedData} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
92
113
  <CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
93
- <XAxis dataKey={resolvedXKey} tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
114
+ <XAxis dataKey={finalXKey} tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
94
115
  <YAxis tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={false} />
95
116
  <Tooltip
96
117
  contentStyle={{ borderRadius: '8px', border: 'none', boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1)' }}
97
118
  cursor={{ fill: '#f1f5f9' }}
98
119
  />
99
120
  <Legend wrapperStyle={{ fontSize: 12 }} />
100
- {resolvedDataKeys.map((key, index) => (
121
+ {finalDataKeys.map((key, index) => (
101
122
  <Bar
102
123
  key={key}
103
124
  dataKey={key}
@@ -108,15 +129,15 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
108
129
  ))}
109
130
  </BarChart>
110
131
  ) : (
111
- <LineChart data={data} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
132
+ <LineChart data={sanitizedData} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
112
133
  <CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e2e8f0" />
113
- <XAxis dataKey={resolvedXKey} tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
134
+ <XAxis dataKey={finalXKey} tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={{ stroke: '#cbd5e1' }} />
114
135
  <YAxis tick={{ fontSize: 12, fill: '#64748b' }} tickLine={false} axisLine={false} />
115
136
  <Tooltip
116
137
  contentStyle={{ borderRadius: '8px', border: 'none', boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1)' }}
117
138
  />
118
139
  <Legend wrapperStyle={{ fontSize: 12 }} />
119
- {resolvedDataKeys.map((key, index) => (
140
+ {finalDataKeys.map((key, index) => (
120
141
  <Line
121
142
  key={key}
122
143
  type="monotone"
@@ -167,11 +167,15 @@ export function MessageBubble({
167
167
  thead: ({...props}) => (
168
168
  <thead className="bg-slate-50 dark:bg-white/5 border-b border-slate-200 dark:border-white/10" {...props} />
169
169
  ),
170
- th: ({...props}) => (
171
- <th className="p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" {...props} />
170
+ th: ({children, ...props}) => (
171
+ <th className="p-3 font-semibold text-slate-700 dark:text-white/90 first:rounded-tl-xl last:rounded-tr-xl" {...props}>
172
+ {typeof children === 'object' && children !== null && !Array.isArray(children) && !(children as any).$$typeof ? JSON.stringify(children) : children}
173
+ </th>
172
174
  ),
173
- td: ({...props}) => (
174
- <td className="p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" {...props} />
175
+ td: ({children, ...props}) => (
176
+ <td className="p-3 border-b border-slate-100 dark:border-white/5 last:border-0 text-slate-600 dark:text-white/70" {...props}>
177
+ {typeof children === 'object' && children !== null && !Array.isArray(children) && !(children as any).$$typeof ? JSON.stringify(children) : children}
178
+ </td>
175
179
  ),
176
180
  code({ inline, className, children, ...props }: React.HTMLAttributes<HTMLElement> & { inline?: boolean }) {
177
181
  const match = /language-(\w+)/.exec(className || '');
@@ -184,38 +188,25 @@ export function MessageBubble({
184
188
  return null;
185
189
  }
186
190
 
187
- // Sanitization helper to handle LLM quirks
191
+ // Optimized sanitization helper to handle LLM quirks
188
192
  const sanitizeJson = (json: string) => {
189
193
  return json
190
194
  // 1. Resolve arithmetic: "value": 495 / 1000 => "value": 0.495
191
- // Matches : number op number
192
195
  .replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
193
- const v1 = parseFloat(n1);
194
- const v2 = parseFloat(n2);
195
- let res = v1;
196
- if (op === '+') res = v1 + v2;
197
- if (op === '-') res = v1 - v2;
198
- if (op === '*') res = v1 * v2;
199
- if (op === '/') res = v1 / v2;
200
- return `: ${res}`;
196
+ const v1 = parseFloat(n1); const v2 = parseFloat(n2);
197
+ const ops: Record<string, number> = { '+': v1 + v2, '-': v1 - v2, '*': v1 * v2, '/': v1 / v2 };
198
+ return `: ${ops[op] ?? v1}`;
201
199
  })
202
- // 2. Quote unquoted keys: { Category: "val" } => { "Category": "val" }
203
- // Matches a word followed by a colon, but not inside a string
200
+ // 2. Quote unquoted keys and fix single quotes
204
201
  .replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":')
205
- // 3. Convert single quotes to double quotes (for delimiters)
206
- // This is a heuristic that replaces ' with " when it looks like a JSON string
207
202
  .replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"')
208
- // 4. Remove trailing commas: [1, 2, 3,] => [1, 2, 3]
203
+ // 3. Syntax cleanup: trailing/missing commas and comments
209
204
  .replace(/,\s*([\]}])/g, '$1')
210
- // 5. Fix missing commas between objects: {}{ } => {},{ }
211
205
  .replace(/}\s*{/g, '},{')
212
206
  .replace(/]\s*\[/g, '],[')
213
- // 6. Remove JS-style comments: // something
214
207
  .replace(/\/\/.*$/gm, '')
215
- // 7. Remove dangling empty strings
216
- .replace(/,\s*""\s*,/g, ',')
217
- .replace(/\{\s*""\s*,/g, '{')
218
- .replace(/,\s*""\s*\}/g, '}');
208
+ // 4. Remove dangling empty strings
209
+ .replace(/([{,])\s*""\s*([,}])/g, '$1$2');
219
210
  };
220
211
 
221
212
  try {
@@ -242,7 +233,7 @@ export function MessageBubble({
242
233
  }
243
234
  return (
244
235
  <code className={className} {...props}>
245
- {children}
236
+ {typeof children === 'string' || typeof children === 'number' ? children : JSON.stringify(children)}
246
237
  </code>
247
238
  );
248
239
  }