@retrivora-ai/rag-engine 1.4.6 → 1.4.8
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-C4KDS26Q.mjs → chunk-YCL23GST.mjs} +12 -19
- package/dist/handlers/index.js +12 -19
- package/dist/handlers/index.mjs +1 -1
- package/dist/index.js +14 -3
- package/dist/index.mjs +14 -3
- package/dist/server.js +12 -19
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
- package/src/components/DynamicChart.tsx +15 -5
- package/src/components/MessageBubble.tsx +5 -0
- package/src/core/Pipeline.ts +13 -20
|
@@ -2261,25 +2261,18 @@ var Pipeline = class {
|
|
|
2261
2261
|
if (this.initialised) return;
|
|
2262
2262
|
const chartInstruction = `
|
|
2263
2263
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
{
|
|
2276
|
-
"type": "bar" | "line" | "pie",
|
|
2277
|
-
"xAxisKey": "name",
|
|
2278
|
-
"dataKeys": ["value"],
|
|
2279
|
-
"data": [{"name": "A", "value": 10}]
|
|
2280
|
-
}
|
|
2281
|
-
\`\`\``;
|
|
2282
|
-
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("```chart")) {
|
|
2264
|
+
### VISUALIZATION PROTOCOL:
|
|
2265
|
+
When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
|
|
2266
|
+
1. Wrap the data in a fenced code block with the language 'chart'.
|
|
2267
|
+
2. Use ONLY valid JSON matching this schema:
|
|
2268
|
+
{
|
|
2269
|
+
"type": "bar" | "line" | "pie",
|
|
2270
|
+
"xAxisKey": "property_for_label",
|
|
2271
|
+
"dataKeys": ["property_for_value"],
|
|
2272
|
+
"data": [{ "property_for_label": "A", "property_for_value": 10 }]
|
|
2273
|
+
}
|
|
2274
|
+
3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
|
|
2275
|
+
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
|
|
2283
2276
|
this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
|
|
2284
2277
|
}
|
|
2285
2278
|
console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
|
package/dist/handlers/index.js
CHANGED
|
@@ -3824,25 +3824,18 @@ var Pipeline = class {
|
|
|
3824
3824
|
if (this.initialised) return;
|
|
3825
3825
|
const chartInstruction = `
|
|
3826
3826
|
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
{
|
|
3839
|
-
"type": "bar" | "line" | "pie",
|
|
3840
|
-
"xAxisKey": "name",
|
|
3841
|
-
"dataKeys": ["value"],
|
|
3842
|
-
"data": [{"name": "A", "value": 10}]
|
|
3843
|
-
}
|
|
3844
|
-
\`\`\``;
|
|
3845
|
-
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("```chart")) {
|
|
3827
|
+
### VISUALIZATION PROTOCOL:
|
|
3828
|
+
When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
|
|
3829
|
+
1. Wrap the data in a fenced code block with the language 'chart'.
|
|
3830
|
+
2. Use ONLY valid JSON matching this schema:
|
|
3831
|
+
{
|
|
3832
|
+
"type": "bar" | "line" | "pie",
|
|
3833
|
+
"xAxisKey": "property_for_label",
|
|
3834
|
+
"dataKeys": ["property_for_value"],
|
|
3835
|
+
"data": [{ "property_for_label": "A", "property_for_value": 10 }]
|
|
3836
|
+
}
|
|
3837
|
+
3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
|
|
3838
|
+
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
|
|
3846
3839
|
this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
|
|
3847
3840
|
}
|
|
3848
3841
|
console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
|
package/dist/handlers/index.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -235,13 +235,21 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
235
235
|
Object.keys(subItem).forEach((sk) => {
|
|
236
236
|
const subVal = subItem[sk];
|
|
237
237
|
if (typeof subVal !== "object" || subVal === null) {
|
|
238
|
-
|
|
238
|
+
if (typeof subVal === "string" && !isNaN(Number(subVal)) && subVal.trim() !== "") {
|
|
239
|
+
newItem[sk] = Number(subVal);
|
|
240
|
+
} else {
|
|
241
|
+
newItem[sk] = subVal;
|
|
242
|
+
}
|
|
239
243
|
}
|
|
240
244
|
});
|
|
241
245
|
}
|
|
242
246
|
});
|
|
243
247
|
} else if (typeof val !== "object" || val === null) {
|
|
244
|
-
|
|
248
|
+
if (typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
|
|
249
|
+
newItem[k] = Number(val);
|
|
250
|
+
} else {
|
|
251
|
+
newItem[k] = val;
|
|
252
|
+
}
|
|
245
253
|
}
|
|
246
254
|
});
|
|
247
255
|
return newItem;
|
|
@@ -250,7 +258,7 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
250
258
|
if (!data || data.length === 0) {
|
|
251
259
|
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "p-4 text-sm text-slate-500" }, "No data available for chart.");
|
|
252
260
|
}
|
|
253
|
-
const firstItem =
|
|
261
|
+
const firstItem = sanitizedData[0];
|
|
254
262
|
const allKeys = Object.keys(firstItem);
|
|
255
263
|
const resolvedXKey = config.xAxisKey && firstItem[config.xAxisKey] !== void 0 ? config.xAxisKey : allKeys.find((k) => k.toLowerCase() === "name" || k.toLowerCase() === "label" || k.toLowerCase() === "category") || allKeys.find((k) => typeof firstItem[k] === "string") || allKeys[0];
|
|
256
264
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
|
|
@@ -497,6 +505,9 @@ function MessageBubble({
|
|
|
497
505
|
}, [sources, isUser]);
|
|
498
506
|
const { productsFromContent, cleanContent } = import_react5.default.useMemo(() => {
|
|
499
507
|
if (isUser) return { productsFromContent: [], cleanContent: message.content };
|
|
508
|
+
if (message.content.includes("```chart")) {
|
|
509
|
+
return { productsFromContent: [], cleanContent: message.content };
|
|
510
|
+
}
|
|
500
511
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
501
512
|
const products = [];
|
|
502
513
|
let content = message.content;
|
package/dist/index.mjs
CHANGED
|
@@ -198,13 +198,21 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
198
198
|
Object.keys(subItem).forEach((sk) => {
|
|
199
199
|
const subVal = subItem[sk];
|
|
200
200
|
if (typeof subVal !== "object" || subVal === null) {
|
|
201
|
-
|
|
201
|
+
if (typeof subVal === "string" && !isNaN(Number(subVal)) && subVal.trim() !== "") {
|
|
202
|
+
newItem[sk] = Number(subVal);
|
|
203
|
+
} else {
|
|
204
|
+
newItem[sk] = subVal;
|
|
205
|
+
}
|
|
202
206
|
}
|
|
203
207
|
});
|
|
204
208
|
}
|
|
205
209
|
});
|
|
206
210
|
} else if (typeof val !== "object" || val === null) {
|
|
207
|
-
|
|
211
|
+
if (typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
|
|
212
|
+
newItem[k] = Number(val);
|
|
213
|
+
} else {
|
|
214
|
+
newItem[k] = val;
|
|
215
|
+
}
|
|
208
216
|
}
|
|
209
217
|
});
|
|
210
218
|
return newItem;
|
|
@@ -213,7 +221,7 @@ function DynamicChart({ config, primaryColor = "#6366f1", accentColor = "#8b5cf6
|
|
|
213
221
|
if (!data || data.length === 0) {
|
|
214
222
|
return /* @__PURE__ */ React4.createElement("div", { className: "p-4 text-sm text-slate-500" }, "No data available for chart.");
|
|
215
223
|
}
|
|
216
|
-
const firstItem =
|
|
224
|
+
const firstItem = sanitizedData[0];
|
|
217
225
|
const allKeys = Object.keys(firstItem);
|
|
218
226
|
const resolvedXKey = config.xAxisKey && firstItem[config.xAxisKey] !== void 0 ? config.xAxisKey : allKeys.find((k) => k.toLowerCase() === "name" || k.toLowerCase() === "label" || k.toLowerCase() === "category") || allKeys.find((k) => typeof firstItem[k] === "string") || allKeys[0];
|
|
219
227
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every((k) => {
|
|
@@ -460,6 +468,9 @@ function MessageBubble({
|
|
|
460
468
|
}, [sources, isUser]);
|
|
461
469
|
const { productsFromContent, cleanContent } = React5.useMemo(() => {
|
|
462
470
|
if (isUser) return { productsFromContent: [], cleanContent: message.content };
|
|
471
|
+
if (message.content.includes("```chart")) {
|
|
472
|
+
return { productsFromContent: [], cleanContent: message.content };
|
|
473
|
+
}
|
|
463
474
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
464
475
|
const products = [];
|
|
465
476
|
let content = message.content;
|
package/dist/server.js
CHANGED
|
@@ -3915,25 +3915,18 @@ var Pipeline = class {
|
|
|
3915
3915
|
if (this.initialised) return;
|
|
3916
3916
|
const chartInstruction = `
|
|
3917
3917
|
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
{
|
|
3930
|
-
"type": "bar" | "line" | "pie",
|
|
3931
|
-
"xAxisKey": "name",
|
|
3932
|
-
"dataKeys": ["value"],
|
|
3933
|
-
"data": [{"name": "A", "value": 10}]
|
|
3934
|
-
}
|
|
3935
|
-
\`\`\``;
|
|
3936
|
-
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("```chart")) {
|
|
3918
|
+
### VISUALIZATION PROTOCOL:
|
|
3919
|
+
When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
|
|
3920
|
+
1. Wrap the data in a fenced code block with the language 'chart'.
|
|
3921
|
+
2. Use ONLY valid JSON matching this schema:
|
|
3922
|
+
{
|
|
3923
|
+
"type": "bar" | "line" | "pie",
|
|
3924
|
+
"xAxisKey": "property_for_label",
|
|
3925
|
+
"dataKeys": ["property_for_value"],
|
|
3926
|
+
"data": [{ "property_for_label": "A", "property_for_value": 10 }]
|
|
3927
|
+
}
|
|
3928
|
+
3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
|
|
3929
|
+
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
|
|
3937
3930
|
this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
|
|
3938
3931
|
}
|
|
3939
3932
|
console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
|
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.4.
|
|
3
|
+
"version": "1.4.8",
|
|
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",
|
|
@@ -29,6 +29,8 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
29
29
|
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
30
30
|
// This prevents the "Objects are not valid as a React child" error in Tooltips/Legends
|
|
31
31
|
// This hook MUST be called before any early returns to satisfy React rules
|
|
32
|
+
// CRITICAL: Sanitize the data array to remove any non-primitive values (objects/arrays)
|
|
33
|
+
// Also ensures numeric strings are converted to actual numbers for Recharts.
|
|
32
34
|
const sanitizedData = React.useMemo(() => {
|
|
33
35
|
if (!data) return [];
|
|
34
36
|
return data.map(item => {
|
|
@@ -36,19 +38,28 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
36
38
|
Object.keys(item).forEach(k => {
|
|
37
39
|
const val = item[k];
|
|
38
40
|
if (Array.isArray(val)) {
|
|
39
|
-
// If the LLM output nested arrays, attempt to flatten them
|
|
40
41
|
val.forEach(subItem => {
|
|
41
42
|
if (typeof subItem === 'object' && subItem !== null) {
|
|
42
43
|
Object.keys(subItem).forEach(sk => {
|
|
43
44
|
const subVal = (subItem as Record<string, unknown>)[sk];
|
|
44
45
|
if (typeof subVal !== 'object' || subVal === null) {
|
|
45
|
-
|
|
46
|
+
// Auto-convert numeric strings
|
|
47
|
+
if (typeof subVal === 'string' && !isNaN(Number(subVal)) && subVal.trim() !== '') {
|
|
48
|
+
newItem[sk] = Number(subVal);
|
|
49
|
+
} else {
|
|
50
|
+
newItem[sk] = subVal as string | number | null;
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
55
|
});
|
|
50
56
|
} else if (typeof val !== 'object' || val === null) {
|
|
51
|
-
|
|
57
|
+
// Auto-convert numeric strings
|
|
58
|
+
if (typeof val === 'string' && !isNaN(Number(val)) && val.trim() !== '') {
|
|
59
|
+
newItem[k] = Number(val);
|
|
60
|
+
} else {
|
|
61
|
+
newItem[k] = val as string | number | null;
|
|
62
|
+
}
|
|
52
63
|
}
|
|
53
64
|
});
|
|
54
65
|
return newItem;
|
|
@@ -60,7 +71,7 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
// Smart key resolution: if the provided keys don't exist in the data, try to guess them
|
|
63
|
-
const firstItem =
|
|
74
|
+
const firstItem = sanitizedData[0];
|
|
64
75
|
const allKeys = Object.keys(firstItem);
|
|
65
76
|
|
|
66
77
|
// Resolve xAxisKey: use provided, fallback to 'name', 'label', 'category', or the first string key
|
|
@@ -71,7 +82,6 @@ export function DynamicChart({ config, primaryColor = '#6366f1', accentColor = '
|
|
|
71
82
|
|| allKeys[0];
|
|
72
83
|
|
|
73
84
|
// Resolve dataKeys: use provided, fallback to 'value', 'count', 'amount', or all numeric keys
|
|
74
|
-
// CRITICAL: Filter out any keys that point to objects/arrays to prevent React render errors
|
|
75
85
|
const resolvedDataKeys = config.dataKeys && config.dataKeys.every(k => {
|
|
76
86
|
const val = firstItem[k];
|
|
77
87
|
return val !== undefined && typeof val !== 'object';
|
|
@@ -313,6 +313,11 @@ export function MessageBubble({
|
|
|
313
313
|
const { productsFromContent, cleanContent } = React.useMemo(() => {
|
|
314
314
|
if (isUser) return { productsFromContent: [] as Product[], cleanContent: message.content };
|
|
315
315
|
|
|
316
|
+
// If the message contains a chart, suppress the product carousel to keep focus on visualization
|
|
317
|
+
if (message.content.includes('```chart')) {
|
|
318
|
+
return { productsFromContent: [] as Product[], cleanContent: message.content };
|
|
319
|
+
}
|
|
320
|
+
|
|
316
321
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
|
|
317
322
|
const products: Product[] = [];
|
|
318
323
|
let content = message.content;
|
package/src/core/Pipeline.ts
CHANGED
|
@@ -99,28 +99,21 @@ export class Pipeline {
|
|
|
99
99
|
async initialize(): Promise<void> {
|
|
100
100
|
if (this.initialised) return;
|
|
101
101
|
|
|
102
|
-
// Augment system prompt with
|
|
103
|
-
const chartInstruction = `\n\
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
"type": "bar" | "line" | "pie",
|
|
116
|
-
"xAxisKey": "name",
|
|
117
|
-
"dataKeys": ["value"],
|
|
118
|
-
"data": [{"name": "A", "value": 10}]
|
|
119
|
-
}
|
|
120
|
-
\`\`\``;
|
|
102
|
+
// Augment system prompt with a Universal Visualization Protocol
|
|
103
|
+
const chartInstruction = `\n\n### VISUALIZATION PROTOCOL:
|
|
104
|
+
When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
|
|
105
|
+
1. Wrap the data in a fenced code block with the language 'chart'.
|
|
106
|
+
2. Use ONLY valid JSON matching this schema:
|
|
107
|
+
{
|
|
108
|
+
"type": "bar" | "line" | "pie",
|
|
109
|
+
"xAxisKey": "property_for_label",
|
|
110
|
+
"dataKeys": ["property_for_value"],
|
|
111
|
+
"data": [{ "property_for_label": "A", "property_for_value": 10 }]
|
|
112
|
+
}
|
|
113
|
+
3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
|
|
121
114
|
|
|
122
115
|
// Inject chart instructions if not already present (including when systemPrompt is undefined)
|
|
123
|
-
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes('
|
|
116
|
+
if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes('chart')) {
|
|
124
117
|
this.config.llm.systemPrompt = (this.config.llm.systemPrompt || '') + chartInstruction;
|
|
125
118
|
}
|
|
126
119
|
|