@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.
- package/dist/{chunk-NXEX6XM6.mjs → chunk-C4UPQX3E.mjs} +8 -9
- package/dist/handlers/index.js +8 -9
- package/dist/handlers/index.mjs +1 -1
- package/dist/index.js +13 -0
- package/dist/index.mjs +13 -0
- package/dist/server.js +8 -9
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/src/components/MessageBubble.tsx +13 -1
- package/src/core/Pipeline.ts +8 -9
|
@@ -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 = "<!--
|
|
2262
|
+
const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
|
|
2263
2263
|
const chartInstruction = `
|
|
2264
2264
|
|
|
2265
2265
|
${CHART_MARKER}
|
|
2266
|
-
###
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
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
|
}
|
package/dist/handlers/index.js
CHANGED
|
@@ -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 = "<!--
|
|
3825
|
+
const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
|
|
3826
3826
|
const chartInstruction = `
|
|
3827
3827
|
|
|
3828
3828
|
${CHART_MARKER}
|
|
3829
|
-
###
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
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
|
}
|
package/dist/handlers/index.mjs
CHANGED
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 = "<!--
|
|
3916
|
+
const CHART_MARKER = "<!-- VIZ_PROTOCOL_V2 -->";
|
|
3917
3917
|
const chartInstruction = `
|
|
3918
3918
|
|
|
3919
3919
|
${CHART_MARKER}
|
|
3920
|
-
###
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "1.5.
|
|
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.
|
|
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`;
|
package/src/core/Pipeline.ts
CHANGED
|
@@ -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 = '<!--
|
|
104
|
+
const CHART_MARKER = '<!-- VIZ_PROTOCOL_V2 -->';
|
|
105
105
|
const chartInstruction = `\n\n${CHART_MARKER}
|
|
106
|
-
###
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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;
|