@retrivora-ai/rag-engine 1.2.5 → 1.2.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/dist/index.js CHANGED
@@ -402,9 +402,13 @@ function MessageBubble({
402
402
  const match = /language-(\w+)/.exec(className || "");
403
403
  const isChart = match && match[1] === "chart";
404
404
  if (!inline && isChart) {
405
- const rawContent = String(children).trim();
405
+ let rawContent = String(children).trim();
406
+ const sanitizeJson = (json) => {
407
+ return json.replace(/:\s*(\d+)\s*\+\s*(\d+)/g, (_, a, b) => `: ${Number(a) + Number(b)}`).replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
408
+ };
406
409
  try {
407
- const config = JSON.parse(rawContent);
410
+ const sanitized = sanitizeJson(rawContent);
411
+ const config = JSON.parse(sanitized);
408
412
  return /* @__PURE__ */ import_react5.default.createElement("div", { className: "my-4 p-4 bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm" }, /* @__PURE__ */ import_react5.default.createElement(
409
413
  DynamicChart,
410
414
  {
@@ -414,7 +418,7 @@ function MessageBubble({
414
418
  }
415
419
  ));
416
420
  } catch (err) {
417
- console.error("[MessageBubble] Chart parsing failed:", err, "\nRaw content:", rawContent);
421
+ console.error("[MessageBubble] Chart parsing failed:", err, "\nSanitized content:", sanitizeJson(rawContent));
418
422
  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."));
419
423
  }
420
424
  }
package/dist/index.mjs CHANGED
@@ -365,9 +365,13 @@ function MessageBubble({
365
365
  const match = /language-(\w+)/.exec(className || "");
366
366
  const isChart = match && match[1] === "chart";
367
367
  if (!inline && isChart) {
368
- const rawContent = String(children).trim();
368
+ let rawContent = String(children).trim();
369
+ const sanitizeJson = (json) => {
370
+ return json.replace(/:\s*(\d+)\s*\+\s*(\d+)/g, (_, a, b) => `: ${Number(a) + Number(b)}`).replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
371
+ };
369
372
  try {
370
- const config = JSON.parse(rawContent);
373
+ const sanitized = sanitizeJson(rawContent);
374
+ const config = JSON.parse(sanitized);
371
375
  return /* @__PURE__ */ React5.createElement("div", { className: "my-4 p-4 bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm" }, /* @__PURE__ */ React5.createElement(
372
376
  DynamicChart,
373
377
  {
@@ -377,7 +381,7 @@ function MessageBubble({
377
381
  }
378
382
  ));
379
383
  } catch (err) {
380
- console.error("[MessageBubble] Chart parsing failed:", err, "\nRaw content:", rawContent);
384
+ console.error("[MessageBubble] Chart parsing failed:", err, "\nSanitized content:", sanitizeJson(rawContent));
381
385
  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."));
382
386
  }
383
387
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
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",
@@ -178,10 +178,22 @@ export function MessageBubble({
178
178
  const isChart = match && match[1] === 'chart';
179
179
 
180
180
  if (!inline && isChart) {
181
- const rawContent = String(children).trim();
181
+ let rawContent = String(children).trim();
182
+
183
+ // Sanitization helper to handle LLM quirks
184
+ const sanitizeJson = (json: string) => {
185
+ return json
186
+ // 1. Resolve simple math: "value": 10 + 20 => "value": 30
187
+ .replace(/:\s*(\d+)\s*\+\s*(\d+)/g, (_, a, b) => `: ${Number(a) + Number(b)}`)
188
+ // 2. Remove dangling empty strings: "key": "val", "", "other": "val" => "key": "val", "other": "val"
189
+ .replace(/,\s*""\s*,/g, ',')
190
+ .replace(/\{\s*""\s*,/g, '{')
191
+ .replace(/,\s*""\s*\}/g, '}');
192
+ };
193
+
182
194
  try {
183
- // Attempt to parse the JSON
184
- const config = JSON.parse(rawContent) as ChartConfig;
195
+ const sanitized = sanitizeJson(rawContent);
196
+ const config = JSON.parse(sanitized) as ChartConfig;
185
197
  return (
186
198
  <div className="my-4 p-4 bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm">
187
199
  <DynamicChart
@@ -192,7 +204,7 @@ export function MessageBubble({
192
204
  </div>
193
205
  );
194
206
  } catch (err) {
195
- console.error('[MessageBubble] Chart parsing failed:', err, '\nRaw content:', rawContent);
207
+ console.error('[MessageBubble] Chart parsing failed:', err, '\nSanitized content:', sanitizeJson(rawContent));
196
208
  return (
197
209
  <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">
198
210
  <p className="font-medium mb-1">Failed to render chart</p>