@retrivora-ai/rag-engine 1.5.4 → 1.5.6

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,23 +2259,70 @@ var Pipeline = class {
2259
2259
  async initialize() {
2260
2260
  var _a, _b;
2261
2261
  if (this.initialised) return;
2262
- const CHART_MARKER = "<!-- UI_PROTOCOL_V3 -->";
2262
+ const CHART_MARKER = "<!-- UI_PROTOCOL_V5 -->";
2263
2263
  const chartInstruction = `
2264
2264
 
2265
2265
  ${CHART_MARKER}
2266
- ### UNIVERSAL UI PROTOCOL:
2267
- You have a specialized UI system. For any structured data (charts, product lists, or tables), you MUST use a single \`\`\`ui\`\`\` block.
2268
- 1. DECIDE the best "view" for the user's query:
2269
- - "chart": For statistics, distributions, or comparisons. (Requires "chartType": "pie" | "bar" | "line")
2270
- - "carousel": For browsing specific product items.
2271
- - "table": For detailed raw data comparisons.
2272
- 2. OUTPUT a \`\`\`ui\`\`\` block with this schema:
2266
+ ### UNIVERSAL UI PROTOCOL
2267
+ When the user asks for a visual representation, comparison, distribution, breakdown, table, list, catalog, products, carousel, stock view, or category summary, you MUST include exactly one \`\`\`ui\`\`\` block.
2268
+
2269
+ 1. VIEW SELECTION
2270
+ - Use "chart" for distributions, percentages, counts, comparisons, trends, or "show me in a chart".
2271
+ - Use "carousel" for browseable product recommendations or when the user asks to see products/items/cards.
2272
+ - Use "table" for tabular/raw detail, explicit table/list requests, or when there are many attributes to compare.
2273
+
2274
+ 2. REQUIRED JSON SHAPE
2273
2275
  {
2274
2276
  "view": "chart" | "carousel" | "table",
2275
- "chartType": "pie" | "bar" | "line" (only for view: "chart"),
2276
- "data": [ ... objects ... ]
2277
+ "title": "Short heading",
2278
+ "description": "One sentence describing the view",
2279
+ "chartType": "pie" | "bar" | "line",
2280
+ "xAxisKey": "label",
2281
+ "dataKeys": ["value"],
2282
+ "columns": ["name", "category", "price", "stockStatus"],
2283
+ "insights": ["Short takeaway 1", "Short takeaway 2"],
2284
+ "data": []
2277
2285
  }
2278
- 3. RULES: Valid JSON only. Data must be FLAT. Never draw charts/tables with text. Choose ONLY the most useful view.`;
2286
+
2287
+ 3. DATA RULES
2288
+ - Build the UI payload from retrieved context only. Do not invent products, categories, or stock values.
2289
+ - Aggregate raw product rows when the user asks for a chart.
2290
+ - For charts, every row in "data" must be flat JSON with primitive values only.
2291
+ - Prefer { "label": "...", "value": number } for pie charts.
2292
+ - If stock information exists, preserve it in each row with fields like "inStock", "inStockCount", "outOfStockCount", or "stockStatus".
2293
+ - If the user asks to highlight what is in stock, include those stock-related fields in the chart data and mention the pattern in "insights".
2294
+ - For carousel rows, include product-friendly fields such as id, name, brand, price, image, link, category, stockStatus.
2295
+ - For tables, keep "data" row-oriented and include "columns" when possible.
2296
+
2297
+ 4. FORMAT RULES
2298
+ - Never use ASCII art, markdown tables as the primary answer, or text-only fake charts when a UI block is requested.
2299
+ - Put any short natural-language explanation before or after the \`\`\`ui\`\`\` block, but keep it concise.
2300
+ - Return valid JSON inside the \`\`\`ui\`\`\` block.
2301
+ - If the user explicitly asks for a pie chart, return "view": "chart" with "chartType": "pie", not a table fallback.
2302
+ - Do not prefix the JSON with labels like "Table View", "Alternative", or explanatory text inside the code block.
2303
+
2304
+ 5. EXAMPLE
2305
+ User: "provide me the distribution of products across categories and highlight which ones are in stock in a pie chart"
2306
+ Assistant:
2307
+ \`\`\`ui
2308
+ {
2309
+ "view": "chart",
2310
+ "title": "Product Distribution Across Categories",
2311
+ "description": "Pie chart showing product count by category with stock signals preserved per slice.",
2312
+ "chartType": "pie",
2313
+ "xAxisKey": "label",
2314
+ "dataKeys": ["value"],
2315
+ "insights": [
2316
+ "Beauty has the highest product count.",
2317
+ "Electronics has the largest number of in-stock products."
2318
+ ],
2319
+ "data": [
2320
+ { "label": "Beauty", "value": 12, "inStockCount": 9, "outOfStockCount": 3 },
2321
+ { "label": "Electronics", "value": 8, "inStockCount": 7, "outOfStockCount": 1 },
2322
+ { "label": "Home", "value": 5, "inStockCount": 2, "outOfStockCount": 3 }
2323
+ ]
2324
+ }
2325
+ \`\`\``;
2279
2326
  if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
2280
2327
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
2281
2328
  }
@@ -3822,23 +3822,70 @@ var Pipeline = class {
3822
3822
  async initialize() {
3823
3823
  var _a, _b;
3824
3824
  if (this.initialised) return;
3825
- const CHART_MARKER = "<!-- UI_PROTOCOL_V3 -->";
3825
+ const CHART_MARKER = "<!-- UI_PROTOCOL_V5 -->";
3826
3826
  const chartInstruction = `
3827
3827
 
3828
3828
  ${CHART_MARKER}
3829
- ### UNIVERSAL UI PROTOCOL:
3830
- You have a specialized UI system. For any structured data (charts, product lists, or tables), you MUST use a single \`\`\`ui\`\`\` block.
3831
- 1. DECIDE the best "view" for the user's query:
3832
- - "chart": For statistics, distributions, or comparisons. (Requires "chartType": "pie" | "bar" | "line")
3833
- - "carousel": For browsing specific product items.
3834
- - "table": For detailed raw data comparisons.
3835
- 2. OUTPUT a \`\`\`ui\`\`\` block with this schema:
3829
+ ### UNIVERSAL UI PROTOCOL
3830
+ When the user asks for a visual representation, comparison, distribution, breakdown, table, list, catalog, products, carousel, stock view, or category summary, you MUST include exactly one \`\`\`ui\`\`\` block.
3831
+
3832
+ 1. VIEW SELECTION
3833
+ - Use "chart" for distributions, percentages, counts, comparisons, trends, or "show me in a chart".
3834
+ - Use "carousel" for browseable product recommendations or when the user asks to see products/items/cards.
3835
+ - Use "table" for tabular/raw detail, explicit table/list requests, or when there are many attributes to compare.
3836
+
3837
+ 2. REQUIRED JSON SHAPE
3836
3838
  {
3837
3839
  "view": "chart" | "carousel" | "table",
3838
- "chartType": "pie" | "bar" | "line" (only for view: "chart"),
3839
- "data": [ ... objects ... ]
3840
+ "title": "Short heading",
3841
+ "description": "One sentence describing the view",
3842
+ "chartType": "pie" | "bar" | "line",
3843
+ "xAxisKey": "label",
3844
+ "dataKeys": ["value"],
3845
+ "columns": ["name", "category", "price", "stockStatus"],
3846
+ "insights": ["Short takeaway 1", "Short takeaway 2"],
3847
+ "data": []
3840
3848
  }
3841
- 3. RULES: Valid JSON only. Data must be FLAT. Never draw charts/tables with text. Choose ONLY the most useful view.`;
3849
+
3850
+ 3. DATA RULES
3851
+ - Build the UI payload from retrieved context only. Do not invent products, categories, or stock values.
3852
+ - Aggregate raw product rows when the user asks for a chart.
3853
+ - For charts, every row in "data" must be flat JSON with primitive values only.
3854
+ - Prefer { "label": "...", "value": number } for pie charts.
3855
+ - If stock information exists, preserve it in each row with fields like "inStock", "inStockCount", "outOfStockCount", or "stockStatus".
3856
+ - If the user asks to highlight what is in stock, include those stock-related fields in the chart data and mention the pattern in "insights".
3857
+ - For carousel rows, include product-friendly fields such as id, name, brand, price, image, link, category, stockStatus.
3858
+ - For tables, keep "data" row-oriented and include "columns" when possible.
3859
+
3860
+ 4. FORMAT RULES
3861
+ - Never use ASCII art, markdown tables as the primary answer, or text-only fake charts when a UI block is requested.
3862
+ - Put any short natural-language explanation before or after the \`\`\`ui\`\`\` block, but keep it concise.
3863
+ - Return valid JSON inside the \`\`\`ui\`\`\` block.
3864
+ - If the user explicitly asks for a pie chart, return "view": "chart" with "chartType": "pie", not a table fallback.
3865
+ - Do not prefix the JSON with labels like "Table View", "Alternative", or explanatory text inside the code block.
3866
+
3867
+ 5. EXAMPLE
3868
+ User: "provide me the distribution of products across categories and highlight which ones are in stock in a pie chart"
3869
+ Assistant:
3870
+ \`\`\`ui
3871
+ {
3872
+ "view": "chart",
3873
+ "title": "Product Distribution Across Categories",
3874
+ "description": "Pie chart showing product count by category with stock signals preserved per slice.",
3875
+ "chartType": "pie",
3876
+ "xAxisKey": "label",
3877
+ "dataKeys": ["value"],
3878
+ "insights": [
3879
+ "Beauty has the highest product count.",
3880
+ "Electronics has the largest number of in-stock products."
3881
+ ],
3882
+ "data": [
3883
+ { "label": "Beauty", "value": 12, "inStockCount": 9, "outOfStockCount": 3 },
3884
+ { "label": "Electronics", "value": 8, "inStockCount": 7, "outOfStockCount": 1 },
3885
+ { "label": "Home", "value": 5, "inStockCount": 2, "outOfStockCount": 3 }
3886
+ ]
3887
+ }
3888
+ \`\`\``;
3842
3889
  if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
3843
3890
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3844
3891
  }
@@ -9,7 +9,7 @@ import {
9
9
  sseFrame,
10
10
  sseMetaFrame,
11
11
  sseTextFrame
12
- } from "../chunk-BLLMNP77.mjs";
12
+ } from "../chunk-ID2Q4CF7.mjs";
13
13
  import "../chunk-YLTMFW4M.mjs";
14
14
  import "../chunk-X4TOT24V.mjs";
15
15
  export {
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as Us
3
3
  export { C as ChatMessage, c as ChatOptions, d as ChatResponse, E as EmbeddingConfig, e as EmbeddingProvider, I as IngestDocument, L as LLMConfig, f as LLMProvider, g as RAGConfig, h as RagConfig, i as UpsertDocument, j as VectorDBConfig, k as VectorDBProvider } from './index-Cti1u0y1.mjs';
4
4
  export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-D1dg5iCi.mjs';
5
5
 
6
+ type ChatViewportSize = 'compact' | 'medium' | 'large';
6
7
  interface ChatWindowProps {
7
8
  /** Additional className for the wrapper div */
8
9
  className?: string;
@@ -38,6 +39,7 @@ interface MessageBubbleProps {
38
39
  primaryColor: string;
39
40
  accentColor: string;
40
41
  onAddToCart?: (product: Product) => void;
42
+ viewportSize?: ChatViewportSize;
41
43
  }
42
44
  interface ProductCardProps {
43
45
  product: Product;
@@ -79,7 +81,7 @@ declare function ChatWindow({ className, style, onClose, showClose, onResizeStar
79
81
 
80
82
  declare function DocumentUpload({ namespace, onUploadComplete, className }: DocumentUploadProps): React.JSX.Element;
81
83
 
82
- declare function MessageBubble({ message, sources, isStreaming, primaryColor, accentColor, onAddToCart, }: MessageBubbleProps): React.JSX.Element;
84
+ declare function MessageBubble({ message, sources, isStreaming, primaryColor, accentColor, onAddToCart, viewportSize, }: MessageBubbleProps): React.JSX.Element;
83
85
 
84
86
  declare function SourceCard({ source, index }: SourceCardProps): React.JSX.Element;
85
87
 
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as Us
3
3
  export { C as ChatMessage, c as ChatOptions, d as ChatResponse, E as EmbeddingConfig, e as EmbeddingProvider, I as IngestDocument, L as LLMConfig, f as LLMProvider, g as RAGConfig, h as RagConfig, i as UpsertDocument, j as VectorDBConfig, k as VectorDBProvider } from './index-Cti1u0y1.js';
4
4
  export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BXOUMKoP.js';
5
5
 
6
+ type ChatViewportSize = 'compact' | 'medium' | 'large';
6
7
  interface ChatWindowProps {
7
8
  /** Additional className for the wrapper div */
8
9
  className?: string;
@@ -38,6 +39,7 @@ interface MessageBubbleProps {
38
39
  primaryColor: string;
39
40
  accentColor: string;
40
41
  onAddToCart?: (product: Product) => void;
42
+ viewportSize?: ChatViewportSize;
41
43
  }
42
44
  interface ProductCardProps {
43
45
  product: Product;
@@ -79,7 +81,7 @@ declare function ChatWindow({ className, style, onClose, showClose, onResizeStar
79
81
 
80
82
  declare function DocumentUpload({ namespace, onUploadComplete, className }: DocumentUploadProps): React.JSX.Element;
81
83
 
82
- declare function MessageBubble({ message, sources, isStreaming, primaryColor, accentColor, onAddToCart, }: MessageBubbleProps): React.JSX.Element;
84
+ declare function MessageBubble({ message, sources, isStreaming, primaryColor, accentColor, onAddToCart, viewportSize, }: MessageBubbleProps): React.JSX.Element;
83
85
 
84
86
  declare function SourceCard({ source, index }: SourceCardProps): React.JSX.Element;
85
87