@retrivora-ai/rag-engine 1.7.6 → 1.7.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.
@@ -10,7 +10,7 @@ import {
10
10
  sseMetaFrame,
11
11
  sseTextFrame,
12
12
  sseUIFrame
13
- } from "../chunk-XGVKIPNY.mjs";
13
+ } from "../chunk-UHGYLTTY.mjs";
14
14
  import "../chunk-YLTMFW4M.mjs";
15
15
  import "../chunk-X4TOT24V.mjs";
16
16
  export {
@@ -1,4 +1,4 @@
1
- import { h as RagConfig, C as ChatMessage, d as ChatResponse, I as IngestDocument } from './index-Cti1u0y1.mjs';
1
+ import { h as RagConfig, C as ChatMessage, d as ChatResponse, I as IngestDocument } from './index-DfsVx0a4.mjs';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  interface ValidationError {
@@ -1,4 +1,4 @@
1
- import { h as RagConfig, C as ChatMessage, d as ChatResponse, I as IngestDocument } from './index-Cti1u0y1.js';
1
+ import { h as RagConfig, C as ChatMessage, d as ChatResponse, I as IngestDocument } from './index-DfsVx0a4.js';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  interface ValidationError {
@@ -6,6 +6,7 @@ interface ChatMessage {
6
6
  interface RagMessage extends ChatMessage {
7
7
  id: string;
8
8
  sources?: VectorMatch[];
9
+ uiTransformation?: any;
9
10
  createdAt: string;
10
11
  }
11
12
  interface ChatOptions {
@@ -6,6 +6,7 @@ interface ChatMessage {
6
6
  interface RagMessage extends ChatMessage {
7
7
  id: string;
8
8
  sources?: VectorMatch[];
9
+ uiTransformation?: any;
9
10
  createdAt: string;
10
11
  }
11
12
  interface ChatOptions {
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties, MouseEvent, ReactNode } from 'react';
2
- import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as UseRagChatOptions, b as UseRagChatReturn } from './index-Cti1u0y1.mjs';
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
- export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-D1dg5iCi.mjs';
2
+ import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as UseRagChatOptions, b as UseRagChatReturn } from './index-DfsVx0a4.mjs';
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-DfsVx0a4.mjs';
4
+ export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-wKE98F_G.mjs';
5
5
 
6
6
  type ChatViewportSize = 'compact' | 'medium' | 'large';
7
7
  interface ChatWindowProps {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties, MouseEvent, ReactNode } from 'react';
2
- import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as UseRagChatOptions, b as UseRagChatReturn } from './index-Cti1u0y1.js';
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
- export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BXOUMKoP.js';
2
+ import { P as Product, U as UIConfig, R as RagMessage, V as VectorMatch, a as UseRagChatOptions, b as UseRagChatReturn } from './index-DfsVx0a4.js';
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-DfsVx0a4.js';
4
+ export { C as Chunk, a as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-DMZVv6hi.js';
5
5
 
6
6
  type ChatViewportSize = 'compact' | 'medium' | 'large';
7
7
  interface ChatWindowProps {
package/dist/index.js CHANGED
@@ -393,6 +393,178 @@ function DynamicChart({
393
393
  ))))));
394
394
  }
395
395
 
396
+ // src/components/VisualizationRenderer.tsx
397
+ var import_image2 = __toESM(require("next/image"));
398
+ function VisualizationRenderer({
399
+ data,
400
+ className = ""
401
+ }) {
402
+ if (!data) {
403
+ return /* @__PURE__ */ React.createElement("div", { className: `p-4 text-gray-500 ${className}` }, "No data available for visualization");
404
+ }
405
+ return /* @__PURE__ */ React.createElement("div", { className: `space-y-4 ${className}` }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white" }, data.title), data.description && /* @__PURE__ */ React.createElement("p", { className: "text-sm text-gray-600 dark:text-gray-400" }, data.description)), renderVisualization(data.type, data.data));
406
+ }
407
+ function renderVisualization(type, data) {
408
+ switch (type) {
409
+ case "pie_chart":
410
+ return renderPieChart(data);
411
+ case "bar_chart":
412
+ return renderBarChart(data);
413
+ case "line_chart":
414
+ return renderLineChart(data);
415
+ case "table":
416
+ return renderTable(data);
417
+ case "product_carousel":
418
+ return renderProductCarousel(data);
419
+ case "text":
420
+ default:
421
+ return renderText(data);
422
+ }
423
+ }
424
+ function renderPieChart(data) {
425
+ if (!Array.isArray(data)) {
426
+ return /* @__PURE__ */ React.createElement("div", { className: "text-red-500" }, "Invalid pie chart data");
427
+ }
428
+ return /* @__PURE__ */ React.createElement("div", { className: "bg-white dark:bg-gray-800 p-4 rounded-lg shadow" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap gap-2" }, data.map((item, idx) => /* @__PURE__ */ React.createElement(
429
+ "div",
430
+ {
431
+ key: idx,
432
+ className: "flex items-center gap-2 p-2 bg-gray-50 dark:bg-gray-700 rounded"
433
+ },
434
+ /* @__PURE__ */ React.createElement(
435
+ "div",
436
+ {
437
+ className: "w-3 h-3 rounded-full",
438
+ style: { backgroundColor: generateColor(idx) }
439
+ }
440
+ ),
441
+ /* @__PURE__ */ React.createElement("span", { className: "text-sm font-medium text-gray-700 dark:text-gray-300" }, item.label, ": ", item.value),
442
+ item.inStock !== void 0 && /* @__PURE__ */ React.createElement(
443
+ "span",
444
+ {
445
+ className: `text-xs px-2 py-1 rounded ${item.inStock ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`
446
+ },
447
+ item.inStock ? "In Stock" : "Out of Stock"
448
+ )
449
+ ))));
450
+ }
451
+ function renderBarChart(data) {
452
+ if (!Array.isArray(data)) {
453
+ return /* @__PURE__ */ React.createElement("div", { className: "text-red-500" }, "Invalid bar chart data");
454
+ }
455
+ return /* @__PURE__ */ React.createElement("div", { className: "bg-white dark:bg-gray-800 p-4 rounded-lg shadow overflow-x-auto" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-3" }, data.map((item, idx) => /* @__PURE__ */ React.createElement("div", { key: idx, className: "space-y-1" }, /* @__PURE__ */ React.createElement("div", { className: "flex justify-between items-center" }, /* @__PURE__ */ React.createElement("span", { className: "text-sm font-medium text-gray-700 dark:text-gray-300" }, item.category), /* @__PURE__ */ React.createElement("span", { className: "text-sm text-gray-600 dark:text-gray-400" }, item.value)), /* @__PURE__ */ React.createElement("div", { className: "w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2" }, /* @__PURE__ */ React.createElement(
456
+ "div",
457
+ {
458
+ className: "h-full rounded-full transition-all",
459
+ style: {
460
+ width: `${item.value / Math.max(...data.map((d) => d.value)) * 100}%`,
461
+ backgroundColor: generateColor(idx)
462
+ }
463
+ }
464
+ )), item.inStock !== void 0 && /* @__PURE__ */ React.createElement(
465
+ "span",
466
+ {
467
+ className: `text-xs px-2 py-1 rounded inline-block ${item.inStock ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`
468
+ },
469
+ item.inStock ? "In Stock" : "Out of Stock"
470
+ )))));
471
+ }
472
+ function renderLineChart(data) {
473
+ if (!Array.isArray(data)) {
474
+ return /* @__PURE__ */ React.createElement("div", { className: "text-red-500" }, "Invalid line chart data");
475
+ }
476
+ return /* @__PURE__ */ React.createElement("div", { className: "bg-white dark:bg-gray-800 p-4 rounded-lg shadow overflow-x-auto" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, data.map((point, idx) => /* @__PURE__ */ React.createElement(
477
+ "div",
478
+ {
479
+ key: idx,
480
+ className: "flex justify-between items-center p-2 bg-gray-50 dark:bg-gray-700 rounded"
481
+ },
482
+ /* @__PURE__ */ React.createElement("span", { className: "text-sm text-gray-600 dark:text-gray-400" }, point.label || point.timestamp),
483
+ /* @__PURE__ */ React.createElement("span", { className: "text-sm font-semibold text-gray-900 dark:text-white" }, typeof point.value === "number" ? point.value.toFixed(2) : point.value)
484
+ ))));
485
+ }
486
+ function renderTable(data) {
487
+ if (!data.columns || !data.rows) {
488
+ return /* @__PURE__ */ React.createElement("div", { className: "text-red-500" }, "Invalid table data");
489
+ }
490
+ return /* @__PURE__ */ React.createElement("div", { className: "bg-white dark:bg-gray-800 rounded-lg shadow overflow-x-auto" }, /* @__PURE__ */ React.createElement("table", { className: "w-full text-sm" }, /* @__PURE__ */ React.createElement("thead", { className: "bg-gray-100 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600" }, /* @__PURE__ */ React.createElement("tr", null, data.columns.map((col, idx) => /* @__PURE__ */ React.createElement(
491
+ "th",
492
+ {
493
+ key: idx,
494
+ className: "px-4 py-2 text-left font-semibold text-gray-900 dark:text-white"
495
+ },
496
+ col
497
+ )))), /* @__PURE__ */ React.createElement("tbody", { className: "divide-y divide-gray-200 dark:divide-gray-600" }, data.rows.map((row, rowIdx) => /* @__PURE__ */ React.createElement(
498
+ "tr",
499
+ {
500
+ key: rowIdx,
501
+ className: "hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors"
502
+ },
503
+ row.map((cell, cellIdx) => /* @__PURE__ */ React.createElement(
504
+ "td",
505
+ {
506
+ key: cellIdx,
507
+ className: "px-4 py-2 text-gray-700 dark:text-gray-300"
508
+ },
509
+ String(cell)
510
+ ))
511
+ )))));
512
+ }
513
+ function renderProductCarousel(data) {
514
+ if (!Array.isArray(data)) {
515
+ return /* @__PURE__ */ React.createElement("div", { className: "text-red-500" }, "Invalid carousel data");
516
+ }
517
+ return /* @__PURE__ */ React.createElement("div", { className: "overflow-x-auto" }, /* @__PURE__ */ React.createElement("div", { className: "flex gap-4 pb-4" }, data.map((product) => /* @__PURE__ */ React.createElement(
518
+ "div",
519
+ {
520
+ key: product.id,
521
+ className: "flex-shrink-0 w-64 bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow"
522
+ },
523
+ product.image && /* @__PURE__ */ React.createElement("div", { className: "relative w-full h-40 bg-gray-200" }, /* @__PURE__ */ React.createElement(
524
+ import_image2.default,
525
+ {
526
+ src: product.image,
527
+ alt: product.name,
528
+ fill: true,
529
+ className: "object-cover",
530
+ sizes: "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
531
+ }
532
+ )),
533
+ /* @__PURE__ */ React.createElement("div", { className: "p-4 space-y-2" }, /* @__PURE__ */ React.createElement("h4", { className: "font-semibold text-gray-900 dark:text-white line-clamp-2" }, product.name), product.brand && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-gray-500 dark:text-gray-400" }, "Brand: ", product.brand), product.price && /* @__PURE__ */ React.createElement("p", { className: "text-lg font-bold text-gray-900 dark:text-white" }, "$", typeof product.price === "number" ? product.price.toFixed(2) : product.price), product.description && /* @__PURE__ */ React.createElement("p", { className: "text-sm text-gray-600 dark:text-gray-400 line-clamp-2" }, product.description), /* @__PURE__ */ React.createElement("div", { className: "flex gap-2 pt-2" }, /* @__PURE__ */ React.createElement(
534
+ "span",
535
+ {
536
+ className: `text-xs px-2 py-1 rounded flex-1 text-center ${product.inStock ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`
537
+ },
538
+ product.inStock ? "In Stock" : "Out of Stock"
539
+ )))
540
+ ))));
541
+ }
542
+ function renderText(data) {
543
+ const content = (data == null ? void 0 : data.content) || String(data);
544
+ return /* @__PURE__ */ React.createElement("div", { className: "bg-white dark:bg-gray-800 p-4 rounded-lg shadow prose dark:prose-invert max-w-none" }, /* @__PURE__ */ React.createElement("p", { className: "text-gray-700 dark:text-gray-300 whitespace-pre-wrap" }, content));
545
+ }
546
+ function generateColor(index) {
547
+ const colors = [
548
+ "#3B82F6",
549
+ // blue
550
+ "#10B981",
551
+ // green
552
+ "#F59E0B",
553
+ // amber
554
+ "#EF4444",
555
+ // red
556
+ "#8B5CF6",
557
+ // purple
558
+ "#EC4899",
559
+ // pink
560
+ "#06B6D4",
561
+ // cyan
562
+ "#F97316"
563
+ // orange
564
+ ];
565
+ return colors[index % colors.length];
566
+ }
567
+
396
568
  // src/components/MessageBubble.tsx
397
569
  function sanitizeJson(raw) {
398
570
  let s = raw.trim();
@@ -1031,7 +1203,7 @@ ${match.trim()}
1031
1203
  onAddToCart,
1032
1204
  viewportSize
1033
1205
  }
1034
- ), !shouldRenderStructuredOnly && /* @__PURE__ */ import_react5.default.createElement(import_react_markdown.default, { remarkPlugins: [import_remark_gfm.default], components: markdownComponents }, processedMarkdown), isStreaming && message.content && /* @__PURE__ */ import_react5.default.createElement("span", { className: "inline-block w-1.5 h-3.5 ml-1 bg-emerald-500 animate-pulse align-middle" }))
1206
+ ), !shouldRenderStructuredOnly && /* @__PURE__ */ import_react5.default.createElement(import_react_markdown.default, { remarkPlugins: [import_remark_gfm.default], components: markdownComponents }, processedMarkdown), !isUser && !structuredContent.payload && message.uiTransformation && /* @__PURE__ */ import_react5.default.createElement("div", { className: "mt-4 border-t border-slate-100 dark:border-white/5 pt-4" }, /* @__PURE__ */ import_react5.default.createElement(VisualizationRenderer, { data: message.uiTransformation })), isStreaming && message.content && /* @__PURE__ */ import_react5.default.createElement("span", { className: "inline-block w-1.5 h-3.5 ml-1 bg-emerald-500 animate-pulse align-middle" }))
1035
1207
  ), !isUser && !hasStructuredProductBlock && allProducts.length > 0 && /* @__PURE__ */ import_react5.default.createElement("div", { className: "w-full mt-1" }, /* @__PURE__ */ import_react5.default.createElement(
1036
1208
  ProductCarousel,
1037
1209
  {
@@ -1125,7 +1297,7 @@ function useConfig() {
1125
1297
  var import_react7 = require("react");
1126
1298
 
1127
1299
  // src/hooks/useStoredMessages.ts
1128
- var React7 = __toESM(require("react"));
1300
+ var React8 = __toESM(require("react"));
1129
1301
  function readStoredMessages(storageKey) {
1130
1302
  if (typeof window === "undefined") {
1131
1303
  return [];
@@ -1142,8 +1314,8 @@ function readStoredMessages(storageKey) {
1142
1314
  }
1143
1315
  }
1144
1316
  function useStoredMessages(storageKey, persist) {
1145
- const [messages, setMessages] = React7.useState(() => persist ? readStoredMessages(storageKey) : []);
1146
- React7.useEffect(() => {
1317
+ const [messages, setMessages] = React8.useState(() => persist ? readStoredMessages(storageKey) : []);
1318
+ React8.useEffect(() => {
1147
1319
  if (!persist || typeof window === "undefined") {
1148
1320
  return;
1149
1321
  }
@@ -1229,6 +1401,7 @@ function useRagChat(projectId, options = {}) {
1229
1401
  const decoder = new TextDecoder();
1230
1402
  let assistantContent = "";
1231
1403
  let sources = [];
1404
+ let uiTransformation = null;
1232
1405
  let buffer = "";
1233
1406
  const assistantMessageId = `assistant_${Date.now()}`;
1234
1407
  setMessages((prev) => [
@@ -1253,13 +1426,19 @@ function useRagChat(projectId, options = {}) {
1253
1426
  assistantContent += frame.text;
1254
1427
  } else if (frame.type === "metadata") {
1255
1428
  sources = (_a = frame.sources) != null ? _a : [];
1429
+ } else if (frame.type === "ui_transformation") {
1430
+ uiTransformation = frame.data;
1256
1431
  } else if (frame.type === "error") {
1257
1432
  setError(frame.error || "Stream error");
1258
1433
  }
1259
1434
  }
1260
1435
  setMessages(
1261
1436
  (prev) => prev.map(
1262
- (msg) => msg.id === assistantMessageId ? __spreadProps(__spreadValues({}, msg), { content: assistantContent, sources: sources.length > 0 ? sources : msg.sources }) : msg
1437
+ (msg) => msg.id === assistantMessageId ? __spreadProps(__spreadValues({}, msg), {
1438
+ content: assistantContent,
1439
+ sources: sources.length > 0 ? sources : msg.sources,
1440
+ uiTransformation: uiTransformation || msg.uiTransformation
1441
+ }) : msg
1263
1442
  )
1264
1443
  );
1265
1444
  }
@@ -1274,6 +1453,7 @@ function useRagChat(projectId, options = {}) {
1274
1453
  role: "assistant",
1275
1454
  content: assistantContent,
1276
1455
  sources: sources.length > 0 ? sources : void 0,
1456
+ uiTransformation: uiTransformation || void 0,
1277
1457
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
1278
1458
  };
1279
1459
  onReply == null ? void 0 : onReply(finalAssistantMessage);