@retrivora-ai/rag-engine 1.2.5 → 1.2.7
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 +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +1 -1
- package/src/components/MessageBubble.tsx +18 -3
package/dist/index.js
CHANGED
|
@@ -403,8 +403,12 @@ function MessageBubble({
|
|
|
403
403
|
const isChart = match && match[1] === "chart";
|
|
404
404
|
if (!inline && isChart) {
|
|
405
405
|
const 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*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
|
|
408
|
+
};
|
|
406
409
|
try {
|
|
407
|
-
const
|
|
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, "\
|
|
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
|
@@ -366,8 +366,12 @@ function MessageBubble({
|
|
|
366
366
|
const isChart = match && match[1] === "chart";
|
|
367
367
|
if (!inline && isChart) {
|
|
368
368
|
const 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*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":').replace(/,\s*""\s*,/g, ",").replace(/\{\s*""\s*,/g, "{").replace(/,\s*""\s*\}/g, "}");
|
|
371
|
+
};
|
|
369
372
|
try {
|
|
370
|
-
const
|
|
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, "\
|
|
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.
|
|
3
|
+
"version": "1.2.7",
|
|
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",
|
|
@@ -179,9 +179,24 @@ export function MessageBubble({
|
|
|
179
179
|
|
|
180
180
|
if (!inline && isChart) {
|
|
181
181
|
const 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. Quote unquoted keys: { Category: "val" } => { "Category": "val" }
|
|
189
|
+
// Matches a word followed by a colon, but not inside a string
|
|
190
|
+
.replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":')
|
|
191
|
+
// 3. Remove dangling empty strings
|
|
192
|
+
.replace(/,\s*""\s*,/g, ',')
|
|
193
|
+
.replace(/\{\s*""\s*,/g, '{')
|
|
194
|
+
.replace(/,\s*""\s*\}/g, '}');
|
|
195
|
+
};
|
|
196
|
+
|
|
182
197
|
try {
|
|
183
|
-
|
|
184
|
-
const config = JSON.parse(
|
|
198
|
+
const sanitized = sanitizeJson(rawContent);
|
|
199
|
+
const config = JSON.parse(sanitized) as ChartConfig;
|
|
185
200
|
return (
|
|
186
201
|
<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
202
|
<DynamicChart
|
|
@@ -192,7 +207,7 @@ export function MessageBubble({
|
|
|
192
207
|
</div>
|
|
193
208
|
);
|
|
194
209
|
} catch (err) {
|
|
195
|
-
console.error('[MessageBubble] Chart parsing failed:', err, '\
|
|
210
|
+
console.error('[MessageBubble] Chart parsing failed:', err, '\nSanitized content:', sanitizeJson(rawContent));
|
|
196
211
|
return (
|
|
197
212
|
<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
213
|
<p className="font-medium mb-1">Failed to render chart</p>
|