@retrivora-ai/rag-engine 1.5.1 → 1.5.2

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.
@@ -2259,18 +2259,17 @@ var Pipeline = class {
2259
2259
  async initialize() {
2260
2260
  var _a, _b;
2261
2261
  if (this.initialised) return;
2262
- const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
2262
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
2263
2263
  const chartInstruction = `
2264
2264
 
2265
2265
  ${CHART_MARKER}
2266
- ### DATA REPRESENTATION TOOLBOX:
2267
- You have two specialized formats for structured data. Choose the one (or both) that provides the most value to the user:
2268
- 1. \`\`\`chart\`\`\` block: Best for statistics, distributions, and comparisons.
2269
- Format: { "type": "bar" | "line" | "pie", "data": [ { "label": "X", "value": 10 } ] }
2270
- 2. \`\`\`json\`\`\` (products) block: Best for listing or browsing specific items.
2271
- Format: { "type": "products", "data": [...] }
2272
-
2273
- RULES: Output MUST be valid JSON. Data objects MUST be FLAT. Never draw charts with text or markdown tables.`;
2266
+ ### MANDATORY VISUALIZATION RULES:
2267
+ - If asked for statistics, distribution, or comparisons: You MUST use the \`\`\`chart block.
2268
+ - FORMAT: \`\`\`chart { "type": "pie" | "bar" | "line", "data": [ { "label": "X", "value": 10 } ] } \`\`\`
2269
+ - RULES:
2270
+ 1. ALWAYS include the \`\`\`chart and \`\`\` markers.
2271
+ 2. NEVER use text, tables, or ASCII art for charts.
2272
+ 3. Output ONLY the chart block. No Python, no text descriptions.`;
2274
2273
  if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
2275
2274
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
2276
2275
  }
@@ -3822,18 +3822,17 @@ var Pipeline = class {
3822
3822
  async initialize() {
3823
3823
  var _a, _b;
3824
3824
  if (this.initialised) return;
3825
- const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
3825
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
3826
3826
  const chartInstruction = `
3827
3827
 
3828
3828
  ${CHART_MARKER}
3829
- ### DATA REPRESENTATION TOOLBOX:
3830
- You have two specialized formats for structured data. Choose the one (or both) that provides the most value to the user:
3831
- 1. \`\`\`chart\`\`\` block: Best for statistics, distributions, and comparisons.
3832
- Format: { "type": "bar" | "line" | "pie", "data": [ { "label": "X", "value": 10 } ] }
3833
- 2. \`\`\`json\`\`\` (products) block: Best for listing or browsing specific items.
3834
- Format: { "type": "products", "data": [...] }
3835
-
3836
- RULES: Output MUST be valid JSON. Data objects MUST be FLAT. Never draw charts with text or markdown tables.`;
3829
+ ### MANDATORY VISUALIZATION RULES:
3830
+ - If asked for statistics, distribution, or comparisons: You MUST use the \`\`\`chart block.
3831
+ - FORMAT: \`\`\`chart { "type": "pie" | "bar" | "line", "data": [ { "label": "X", "value": 10 } ] } \`\`\`
3832
+ - RULES:
3833
+ 1. ALWAYS include the \`\`\`chart and \`\`\` markers.
3834
+ 2. NEVER use text, tables, or ASCII art for charts.
3835
+ 3. Output ONLY the chart block. No Python, no text descriptions.`;
3837
3836
  if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
3838
3837
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3839
3838
  }
@@ -9,7 +9,7 @@ import {
9
9
  sseFrame,
10
10
  sseMetaFrame,
11
11
  sseTextFrame
12
- } from "../chunk-NXEX6XM6.mjs";
12
+ } from "../chunk-C4UPQX3E.mjs";
13
13
  import "../chunk-YLTMFW4M.mjs";
14
14
  import "../chunk-X4TOT24V.mjs";
15
15
  export {
package/dist/index.js CHANGED
@@ -550,6 +550,19 @@ function MessageBubble({
550
550
  const processedMarkdown = import_react5.default.useMemo(() => {
551
551
  let raw = cleanContent || message.content;
552
552
  raw = raw.replace(/([^\n])\n\|/g, "$1\n\n|").replace(/(\|[^\n]*\|)\n\n+(?=\|)/g, "$1\n");
553
+ if (!isStreaming) {
554
+ raw = raw.replace(/(?:^|\n)\s*\{\s*[\s\S]*?"type":\s*"(?:pie|bar|line|products)"[\s\S]*?\}\s*(?:\n|$)/g, (match) => {
555
+ if (match.includes("```")) return match;
556
+ const type = match.includes('"products"') ? "json" : "chart";
557
+ return `
558
+
559
+ \`\`\`${type}
560
+ ${match.trim()}
561
+ \`\`\`
562
+
563
+ `;
564
+ });
565
+ }
553
566
  if (isStreaming) {
554
567
  raw = raw.replace(/((?:^|\n)\|.*)+/g, (match) => {
555
568
  return `
package/dist/index.mjs CHANGED
@@ -513,6 +513,19 @@ function MessageBubble({
513
513
  const processedMarkdown = React5.useMemo(() => {
514
514
  let raw = cleanContent || message.content;
515
515
  raw = raw.replace(/([^\n])\n\|/g, "$1\n\n|").replace(/(\|[^\n]*\|)\n\n+(?=\|)/g, "$1\n");
516
+ if (!isStreaming) {
517
+ raw = raw.replace(/(?:^|\n)\s*\{\s*[\s\S]*?"type":\s*"(?:pie|bar|line|products)"[\s\S]*?\}\s*(?:\n|$)/g, (match) => {
518
+ if (match.includes("```")) return match;
519
+ const type = match.includes('"products"') ? "json" : "chart";
520
+ return `
521
+
522
+ \`\`\`${type}
523
+ ${match.trim()}
524
+ \`\`\`
525
+
526
+ `;
527
+ });
528
+ }
516
529
  if (isStreaming) {
517
530
  raw = raw.replace(/((?:^|\n)\|.*)+/g, (match) => {
518
531
  return `
package/dist/server.js CHANGED
@@ -3913,18 +3913,17 @@ var Pipeline = class {
3913
3913
  async initialize() {
3914
3914
  var _a, _b;
3915
3915
  if (this.initialised) return;
3916
- const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
3916
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
3917
3917
  const chartInstruction = `
3918
3918
 
3919
3919
  ${CHART_MARKER}
3920
- ### DATA REPRESENTATION TOOLBOX:
3921
- You have two specialized formats for structured data. Choose the one (or both) that provides the most value to the user:
3922
- 1. \`\`\`chart\`\`\` block: Best for statistics, distributions, and comparisons.
3923
- Format: { "type": "bar" | "line" | "pie", "data": [ { "label": "X", "value": 10 } ] }
3924
- 2. \`\`\`json\`\`\` (products) block: Best for listing or browsing specific items.
3925
- Format: { "type": "products", "data": [...] }
3926
-
3927
- RULES: Output MUST be valid JSON. Data objects MUST be FLAT. Never draw charts with text or markdown tables.`;
3920
+ ### MANDATORY VISUALIZATION RULES:
3921
+ - If asked for statistics, distribution, or comparisons: You MUST use the \`\`\`chart block.
3922
+ - FORMAT: \`\`\`chart { "type": "pie" | "bar" | "line", "data": [ { "label": "X", "value": 10 } ] } \`\`\`
3923
+ - RULES:
3924
+ 1. ALWAYS include the \`\`\`chart and \`\`\` markers.
3925
+ 2. NEVER use text, tables, or ASCII art for charts.
3926
+ 3. Output ONLY the chart block. No Python, no text descriptions.`;
3928
3927
  if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
3929
3928
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3930
3929
  }
package/dist/server.mjs CHANGED
@@ -39,7 +39,7 @@ import {
39
39
  sseFrame,
40
40
  sseMetaFrame,
41
41
  sseTextFrame
42
- } from "./chunk-NXEX6XM6.mjs";
42
+ } from "./chunk-C4UPQX3E.mjs";
43
43
  import "./chunk-YLTMFW4M.mjs";
44
44
  import {
45
45
  PineconeProvider
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
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",
@@ -366,7 +366,19 @@ export function MessageBubble({
366
366
  raw = raw.replace(/([^\n])\n\|/g, '$1\n\n|') // Ensure blank line before table
367
367
  .replace(/(\|[^\n]*\|)\n\n+(?=\|)/g, '$1\n'); // Remove blank lines between rows
368
368
 
369
- // 2. HIJACKING: If streaming, hide table-like content to prevent raw markdown flashing.
369
+ // 2. HEALING: Detect naked JSON charts/products and wrap them if markers are missing
370
+ // This handles models (like Llama 3.2) that often omit the ```chart markers.
371
+ if (!isStreaming) {
372
+ // Look for objects that look like chart or product data
373
+ raw = raw.replace(/(?:^|\n)\s*\{\s*[\s\S]*?"type":\s*"(?:pie|bar|line|products)"[\s\S]*?\}\s*(?:\n|$)/g, (match) => {
374
+ // Only wrap if not already in a code block
375
+ if (match.includes('```')) return match;
376
+ const type = match.includes('"products"') ? 'json' : 'chart';
377
+ return `\n\n\`\`\`${type}\n${match.trim()}\n\`\`\`\n\n`;
378
+ });
379
+ }
380
+
381
+ // 3. HIJACKING: If streaming, hide table-like content to prevent raw markdown flashing.
370
382
  if (isStreaming) {
371
383
  raw = raw.replace(/((?:^|\n)\|.*)+/g, (match) => {
372
384
  return `\n\n\`\`\`table-loading\n${match.trim()}\n\`\`\`\n\n`;
@@ -101,16 +101,15 @@ export class Pipeline {
101
101
 
102
102
  // Augment system prompt with a Universal Visualization Protocol
103
103
  // We use a unique marker to ensure this is only injected once but is ALWAYS present.
104
- const CHART_MARKER = '<!-- VIZ_PROTOCOL_V1 -->';
104
+ const CHART_MARKER = '<!-- VIZ_PROTOCOL_V2 -->';
105
105
  const chartInstruction = `\n\n${CHART_MARKER}
106
- ### DATA REPRESENTATION TOOLBOX:
107
- You have two specialized formats for structured data. Choose the one (or both) that provides the most value to the user:
108
- 1. \`\`\`chart\`\`\` block: Best for statistics, distributions, and comparisons.
109
- Format: { "type": "bar" | "line" | "pie", "data": [ { "label": "X", "value": 10 } ] }
110
- 2. \`\`\`json\`\`\` (products) block: Best for listing or browsing specific items.
111
- Format: { "type": "products", "data": [...] }
112
-
113
- RULES: Output MUST be valid JSON. Data objects MUST be FLAT. Never draw charts with text or markdown tables.`;
106
+ ### MANDATORY VISUALIZATION RULES:
107
+ - If asked for statistics, distribution, or comparisons: You MUST use the \`\`\`chart block.
108
+ - FORMAT: \`\`\`chart { "type": "pie" | "bar" | "line", "data": [ { "label": "X", "value": 10 } ] } \`\`\`
109
+ - RULES:
110
+ 1. ALWAYS include the \`\`\`chart and \`\`\` markers.
111
+ 2. NEVER use text, tables, or ASCII art for charts.
112
+ 3. Output ONLY the chart block. No Python, no text descriptions.`;
114
113
 
115
114
  if (!this.config.llm.systemPrompt?.includes(CHART_MARKER)) {
116
115
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || '') + chartInstruction;