@retrivora-ai/rag-engine 1.2.8 → 1.3.0

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
@@ -409,9 +409,21 @@ function MessageBubble({
409
409
  const match = /language-(\w+)/.exec(className || "");
410
410
  const isChart = match && match[1] === "chart";
411
411
  if (!inline && isChart) {
412
- const rawContent = String(children).trim();
412
+ const rawContent = String(children || "").trim();
413
+ if (!rawContent || rawContent === "undefined") {
414
+ return null;
415
+ }
413
416
  const sanitizeJson = (json) => {
414
- 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, "}");
417
+ return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
418
+ const v1 = parseFloat(n1);
419
+ 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, "}");
415
427
  };
416
428
  try {
417
429
  const sanitized = sanitizeJson(rawContent);
package/dist/index.mjs CHANGED
@@ -372,9 +372,21 @@ function MessageBubble({
372
372
  const match = /language-(\w+)/.exec(className || "");
373
373
  const isChart = match && match[1] === "chart";
374
374
  if (!inline && isChart) {
375
- const rawContent = String(children).trim();
375
+ const rawContent = String(children || "").trim();
376
+ if (!rawContent || rawContent === "undefined") {
377
+ return null;
378
+ }
376
379
  const sanitizeJson = (json) => {
377
- 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, "}");
380
+ return json.replace(/:\s*(\d+(\.\d+)?)\s*([\+\-\*\/])\s*(\d+(\.\d+)?)/g, (_, n1, __, op, n2) => {
381
+ const v1 = parseFloat(n1);
382
+ 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, "}");
378
390
  };
379
391
  try {
380
392
  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.8",
3
+ "version": "1.3.0",
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,17 +178,41 @@ 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
+ const rawContent = String(children || '').trim();
182
+
183
+ if (!rawContent || rawContent === 'undefined') {
184
+ return null;
185
+ }
182
186
 
183
187
  // Sanitization helper to handle LLM quirks
184
188
  const sanitizeJson = (json: string) => {
185
189
  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)}`)
190
+ // 1. Resolve arithmetic: "value": 495 / 1000 => "value": 0.495
191
+ // Matches : number op number
192
+ .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}`;
201
+ })
188
202
  // 2. Quote unquoted keys: { Category: "val" } => { "Category": "val" }
189
203
  // Matches a word followed by a colon, but not inside a string
190
204
  .replace(/([{,])\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*:/g, '$1 "$2":')
191
- // 3. Remove dangling empty strings
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
+ .replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, '"$1"')
208
+ // 4. Remove trailing commas: [1, 2, 3,] => [1, 2, 3]
209
+ .replace(/,\s*([\]}])/g, '$1')
210
+ // 5. Fix missing commas between objects: {}{ } => {},{ }
211
+ .replace(/}\s*{/g, '},{')
212
+ .replace(/]\s*\[/g, '],[')
213
+ // 6. Remove JS-style comments: // something
214
+ .replace(/\/\/.*$/gm, '')
215
+ // 7. Remove dangling empty strings
192
216
  .replace(/,\s*""\s*,/g, ',')
193
217
  .replace(/\{\s*""\s*,/g, '{')
194
218
  .replace(/,\s*""\s*\}/g, '}');