@retrivora-ai/rag-engine 1.2.8 → 1.2.9
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 +10 -1
- package/dist/index.mjs +10 -1
- package/package.json +1 -1
- package/src/components/MessageBubble.tsx +23 -3
package/dist/index.js
CHANGED
|
@@ -411,7 +411,16 @@ function MessageBubble({
|
|
|
411
411
|
if (!inline && isChart) {
|
|
412
412
|
const rawContent = String(children).trim();
|
|
413
413
|
const sanitizeJson = (json) => {
|
|
414
|
-
return json.replace(/:\s*(\d+)\s
|
|
414
|
+
return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
|
|
415
|
+
const v1 = parseFloat(n1);
|
|
416
|
+
const v2 = parseFloat(n2);
|
|
417
|
+
let res = v1;
|
|
418
|
+
if (op === "+") res = v1 + v2;
|
|
419
|
+
if (op === "-") res = v1 - v2;
|
|
420
|
+
if (op === "*") res = v1 * v2;
|
|
421
|
+
if (op === "/") res = v1 / v2;
|
|
422
|
+
return `: ${res}`;
|
|
423
|
+
}).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, "}");
|
|
415
424
|
};
|
|
416
425
|
try {
|
|
417
426
|
const sanitized = sanitizeJson(rawContent);
|
package/dist/index.mjs
CHANGED
|
@@ -374,7 +374,16 @@ function MessageBubble({
|
|
|
374
374
|
if (!inline && isChart) {
|
|
375
375
|
const rawContent = String(children).trim();
|
|
376
376
|
const sanitizeJson = (json) => {
|
|
377
|
-
return json.replace(/:\s*(\d+)\s
|
|
377
|
+
return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
|
|
378
|
+
const v1 = parseFloat(n1);
|
|
379
|
+
const v2 = parseFloat(n2);
|
|
380
|
+
let res = v1;
|
|
381
|
+
if (op === "+") res = v1 + v2;
|
|
382
|
+
if (op === "-") res = v1 - v2;
|
|
383
|
+
if (op === "*") res = v1 * v2;
|
|
384
|
+
if (op === "/") res = v1 / v2;
|
|
385
|
+
return `: ${res}`;
|
|
386
|
+
}).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, "}");
|
|
378
387
|
};
|
|
379
388
|
try {
|
|
380
389
|
const sanitized = sanitizeJson(rawContent);
|
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.9",
|
|
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",
|
|
@@ -183,12 +183,32 @@ export function MessageBubble({
|
|
|
183
183
|
// Sanitization helper to handle LLM quirks
|
|
184
184
|
const sanitizeJson = (json: string) => {
|
|
185
185
|
return json
|
|
186
|
-
// 1. Resolve
|
|
187
|
-
|
|
186
|
+
// 1. Resolve arithmetic: "value": 495 / 1000 => "value": 0.495
|
|
187
|
+
// Matches : number op number
|
|
188
|
+
.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
|
|
189
|
+
const v1 = parseFloat(n1);
|
|
190
|
+
const v2 = parseFloat(n2);
|
|
191
|
+
let res = v1;
|
|
192
|
+
if (op === '+') res = v1 + v2;
|
|
193
|
+
if (op === '-') res = v1 - v2;
|
|
194
|
+
if (op === '*') res = v1 * v2;
|
|
195
|
+
if (op === '/') res = v1 / v2;
|
|
196
|
+
return `: ${res}`;
|
|
197
|
+
})
|
|
188
198
|
// 2. Quote unquoted keys: { Category: "val" } => { "Category": "val" }
|
|
189
199
|
// Matches a word followed by a colon, but not inside a string
|
|
190
200
|
.replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":')
|
|
191
|
-
// 3.
|
|
201
|
+
// 3. Convert single quotes to double quotes (for delimiters)
|
|
202
|
+
// This is a heuristic that replaces ' with " when it looks like a JSON string
|
|
203
|
+
.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"')
|
|
204
|
+
// 4. Remove trailing commas: [1, 2, 3,] => [1, 2, 3]
|
|
205
|
+
.replace(/,\s*([\]}])/g, '$1')
|
|
206
|
+
// 5. Fix missing commas between objects: {}{ } => {},{ }
|
|
207
|
+
.replace(/}\s*{/g, '},{')
|
|
208
|
+
.replace(/]\s*\[/g, '],[')
|
|
209
|
+
// 6. Remove JS-style comments: // something
|
|
210
|
+
.replace(/\/\/.*$/gm, '')
|
|
211
|
+
// 7. Remove dangling empty strings
|
|
192
212
|
.replace(/,\s*""\s*,/g, ',')
|
|
193
213
|
.replace(/\{\s*""\s*,/g, '{')
|
|
194
214
|
.replace(/,\s*""\s*\}/g, '}');
|