@retrivora-ai/rag-engine 2.3.9 → 2.4.1

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.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/dist/{BatchProcessor-C42_RVWO.d.ts → BatchProcessor-D42E706a.d.ts} +12 -1
  3. package/dist/{BatchProcessor-BhLczWj5.d.mts → BatchProcessor-zbQMaZHm.d.mts} +12 -1
  4. package/dist/{ILLMProvider-B8TAVx3j.d.mts → ILLMProvider-Y6aL5N8J.d.mts} +1 -0
  5. package/dist/{ILLMProvider-B8TAVx3j.d.ts → ILLMProvider-Y6aL5N8J.d.ts} +1 -0
  6. package/dist/handlers/index.d.mts +2 -2
  7. package/dist/handlers/index.d.ts +2 -2
  8. package/dist/handlers/index.js +26 -85
  9. package/dist/handlers/index.mjs +26 -85
  10. package/dist/{index-C7aHK7_g.d.mts → index-59CHg0V3.d.mts} +1 -1
  11. package/dist/{index-BQd6Bax0.d.ts → index-BgKRInpa.d.ts} +1 -1
  12. package/dist/index.css +83 -0
  13. package/dist/index.d.mts +5 -5
  14. package/dist/index.d.ts +5 -5
  15. package/dist/index.js +482 -260
  16. package/dist/index.mjs +494 -269
  17. package/dist/server.d.mts +9 -6
  18. package/dist/server.d.ts +9 -6
  19. package/dist/server.js +34 -118
  20. package/dist/server.mjs +34 -118
  21. package/package.json +1 -1
  22. package/src/LicensedRetrivora.ts +21 -16
  23. package/src/components/ChatWindow.tsx +296 -28
  24. package/src/components/ConfigProvider.tsx +10 -1
  25. package/src/components/DocumentUpload.tsx +28 -29
  26. package/src/components/UIDispatcher.tsx +1 -1
  27. package/src/config/LicenseConfigResolver.ts +14 -12
  28. package/src/config/RagConfig.ts +1 -0
  29. package/src/config/serverConfig.ts +31 -29
  30. package/src/config/uiConstants.ts +1 -0
  31. package/src/core/ConfigFetcher.ts +2 -2
  32. package/src/core/LLMRouter.ts +3 -3
  33. package/src/core/PluginManager.ts +5 -5
  34. package/src/core/mcp.ts +5 -5
  35. package/src/handlers/index.ts +11 -5
  36. package/src/hooks/useRagChat.ts +13 -13
  37. package/src/index.css +83 -0
  38. package/src/llm/LLMFactory.ts +1 -1
  39. package/src/llm/providers/UniversalLLMAdapter.ts +18 -18
  40. package/src/providers/graphdb/SimpleGraphProvider.ts +5 -5
  41. package/src/providers/vectordb/ChromaDBProvider.ts +4 -4
  42. package/src/providers/vectordb/MultiTablePostgresProvider.ts +32 -32
  43. package/src/providers/vectordb/QdrantProvider.ts +17 -17
  44. package/src/telemetry/TelemetryService.ts +12 -12
  45. package/src/types/props.ts +11 -0
  46. package/src/utils/SchemaMapper.ts +1 -1
  47. package/src/utils/UITransformer.ts +1 -1
@@ -10,12 +10,12 @@
10
10
  * Do NOT import in client components.
11
11
  */
12
12
 
13
- import { LicenseConfigResolver } from './config/LicenseConfigResolver';
13
+ import { LicenseConfigResolver, LicenseTierConfig } from './config/LicenseConfigResolver';
14
14
  import { Pipeline } from './core/Pipeline';
15
15
  import { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig } from './config/RagConfig';
16
- import {
17
- initializeTelemetryService,
18
- getTelemetryService,
16
+ import {
17
+ initializeTelemetryService,
18
+ getTelemetryService,
19
19
  shutdownTelemetryService,
20
20
  EventType,
21
21
  } from './telemetry/TelemetryService';
@@ -36,6 +36,7 @@ export class LicensedRetrivora {
36
36
  private projectId: string;
37
37
  private pipeline?: Pipeline;
38
38
  private ragConfig?: RagConfig;
39
+ private tierConfig?: LicenseTierConfig;
39
40
  private initialized: boolean = false;
40
41
 
41
42
  constructor(options: LicensedRetrivoraOptions) {
@@ -60,18 +61,20 @@ export class LicensedRetrivora {
60
61
  */
61
62
  async initialize(): Promise<void> {
62
63
  if (this.initialized) {
63
- console.log('[LicensedRetrivora] Already initialized');
64
+ //console.log('[LicensedRetrivora] Already initialized');
64
65
  return;
65
66
  }
66
67
 
67
- console.log('[LicensedRetrivora] Initializing with license key...');
68
+ //console.log('[LicensedRetrivora] Initializing with license key...');
68
69
  const operationId = this.generateId();
69
70
 
70
71
  try {
71
72
  // Resolve configuration from license tier
72
- const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } =
73
+ const { llmConfig, embeddingConfig, vectorDbConfig, tierConfig } =
73
74
  await LicenseConfigResolver.resolveFromLicense(this.licenseKey, this.projectId);
74
75
 
76
+ this.tierConfig = tierConfig;
77
+
75
78
  // Log successful configuration load
76
79
  const telemetry = getTelemetryService();
77
80
  if (telemetry) {
@@ -111,7 +114,7 @@ export class LicensedRetrivora {
111
114
  await this.pipeline.initialize();
112
115
 
113
116
  this.initialized = true;
114
- console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
117
+ //console.log(`[LicensedRetrivora] Initialized successfully for tier: ${tierConfig.tier}`);
115
118
  } catch (error) {
116
119
  const telemetry = getTelemetryService();
117
120
  if (telemetry && error instanceof Error) {
@@ -136,7 +139,7 @@ export class LicensedRetrivora {
136
139
  const startTime = Date.now();
137
140
 
138
141
  try {
139
- console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
142
+ //console.log(`[LicensedRetrivora] Starting ingestion of ${documents.length} document(s)`);
140
143
 
141
144
  // Ingest documents
142
145
  const results = await this.pipeline.ingest(documents);
@@ -146,10 +149,12 @@ export class LicensedRetrivora {
146
149
  // Record successful ingestion
147
150
  if (telemetry) {
148
151
  for (const result of results) {
152
+ const origDoc = documents.find(d => String(d.docId) === String(result.docId));
153
+ const size = origDoc ? new TextEncoder().encode(origDoc.content).length : 0;
149
154
  telemetry.recordDocumentIngested({
150
155
  documentId: String(result.docId),
151
156
  documentName: String(result.docId),
152
- documentSize: 0, // TODO: track actual size
157
+ documentSize: size,
153
158
  chunksGenerated: result.chunksIngested,
154
159
  durationMs,
155
160
  });
@@ -164,7 +169,7 @@ export class LicensedRetrivora {
164
169
  };
165
170
  } catch (error) {
166
171
  const durationMs = Date.now() - startTime;
167
-
172
+
168
173
  if (telemetry && error instanceof Error) {
169
174
  telemetry.recordError(error, { operationId, durationMs });
170
175
  await telemetry.flush();
@@ -189,7 +194,7 @@ export class LicensedRetrivora {
189
194
  const startTime = Date.now();
190
195
 
191
196
  try {
192
- console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
197
+ //console.log(`[LicensedRetrivora] Executing query: "${queryText.substring(0, 100)}..."`);
193
198
 
194
199
  // Execute query
195
200
  const response = await this.pipeline.runNormalQuery(queryText);
@@ -213,7 +218,7 @@ export class LicensedRetrivora {
213
218
  };
214
219
  } catch (error) {
215
220
  const durationMs = Date.now() - startTime;
216
-
221
+
217
222
  if (telemetry && error instanceof Error) {
218
223
  telemetry.recordError(error, { operationId, durationMs });
219
224
  await telemetry.flush();
@@ -228,12 +233,12 @@ export class LicensedRetrivora {
228
233
  * Get license tier information (for UI display if needed)
229
234
  */
230
235
  async getTierInfo(): Promise<{ tier: string; model: string; embeddingModel: string }> {
231
- if (!this.ragConfig) {
236
+ if (!this.ragConfig || !this.tierConfig) {
232
237
  throw new Error('[LicensedRetrivora] SDK not initialized.');
233
238
  }
234
239
 
235
240
  return {
236
- tier: 'Standard', // TODO: fetch from tier config
241
+ tier: this.tierConfig.tier,
237
242
  model: this.ragConfig.llm.model,
238
243
  embeddingModel: this.ragConfig.embedding.model,
239
244
  };
@@ -245,7 +250,7 @@ export class LicensedRetrivora {
245
250
  async shutdown(): Promise<void> {
246
251
  await shutdownTelemetryService();
247
252
  this.initialized = false;
248
- console.log('[LicensedRetrivora] Shutdown complete');
253
+ //console.log('[LicensedRetrivora] Shutdown complete');
249
254
  }
250
255
 
251
256
  /**
@@ -28,6 +28,9 @@ import {
28
28
  Mic,
29
29
  MicOff,
30
30
  Paperclip,
31
+ MessageSquare,
32
+ Plus,
33
+ Trash,
31
34
  } from 'lucide-react';
32
35
  import { DocumentUpload } from './DocumentUpload';
33
36
  import { MessageBubble } from './MessageBubble';
@@ -104,7 +107,9 @@ export function ChatWindow({
104
107
  apiUrl,
105
108
  retrivoraApiBase,
106
109
  licenseKey: licenseKeyProp,
107
- headers
110
+ headers,
111
+ sessionId: sessionIdProp,
112
+ showHistory = false,
108
113
  }: ChatWindowProps) {
109
114
  const {
110
115
  ui,
@@ -123,15 +128,94 @@ export function ChatWindow({
123
128
  const windowRef = useRef<HTMLDivElement>(null);
124
129
  const bottomRef = useRef<HTMLDivElement>(null);
125
130
  const inputRef = useRef<HTMLTextAreaElement>(null);
126
- const { messages, send, clear, isLoading, error, stop, submitFeedback } = useRagChat(projectId, {
131
+
132
+ // Manage active session ID internally if showHistory is enabled
133
+ const [internalSessionId, setInternalSessionId] = useState(sessionIdProp || 'default');
134
+ const activeSessionId = sessionIdProp || internalSessionId;
135
+
136
+ const {
137
+ messages,
138
+ send,
139
+ clear,
140
+ isLoading,
141
+ error,
142
+ stop,
143
+ submitFeedback,
144
+ loadHistory,
145
+ clearHistory: dbClearHistory
146
+ } = useRagChat(projectId, {
127
147
  namespace: projectId,
128
148
  apiUrl,
129
149
  retrivoraApiBase: effectiveApiBase,
130
150
  licenseKey: effectiveLicenseKey,
131
151
  headers: effectiveHeaders,
132
152
  persist: projectSettings?.widget.persistConversations,
153
+ sessionId: activeSessionId,
133
154
  });
134
155
 
156
+ // Automatically fetch conversation history when activeSessionId changes
157
+ useEffect(() => {
158
+ if (activeSessionId) {
159
+ loadHistory(activeSessionId);
160
+ }
161
+ }, [activeSessionId, loadHistory]);
162
+
163
+ const [sessions, setSessions] = useState<{ id: string; title: string; lastMessageAt?: string }[]>([]);
164
+
165
+ const fetchSessions = useCallback(async () => {
166
+ try {
167
+ const base = effectiveApiBase || '/api/retrivora';
168
+ const res = await fetch(`${base}/sessions`);
169
+ if (res.ok) {
170
+ const data = await res.json();
171
+ if (data.sessions) {
172
+ const normalized = data.sessions.map((s: any) => {
173
+ if (typeof s === 'string') {
174
+ let lastMsgTime: string | undefined = undefined;
175
+ try {
176
+ const parts = s.split('_');
177
+ if (parts.length > 1) {
178
+ const ts = parseInt(parts[1], 10);
179
+ if (!isNaN(ts)) {
180
+ lastMsgTime = new Date(ts).toISOString();
181
+ }
182
+ }
183
+ } catch {}
184
+ return {
185
+ id: s,
186
+ title: s.startsWith('session_')
187
+ ? 'Chat Session'
188
+ : s === 'default' ? 'Main Session' : s,
189
+ lastMessageAt: lastMsgTime
190
+ };
191
+ }
192
+ return {
193
+ id: s?.id || String(s),
194
+ title: s?.title || (s?.id && s.id.startsWith('session_') ? `Chat Session` : s?.id || String(s)),
195
+ lastMessageAt: s?.lastMessageAt
196
+ };
197
+ });
198
+ setSessions(normalized);
199
+ }
200
+ }
201
+ } catch (e) {
202
+ console.warn('[ChatWindow] Failed to load sessions list:', e);
203
+ }
204
+ }, [effectiveApiBase]);
205
+
206
+ useEffect(() => {
207
+ if (showHistory && mounted) {
208
+ fetchSessions();
209
+ }
210
+ }, [showHistory, mounted, fetchSessions, activeSessionId]);
211
+
212
+ // Refresh sessions list when a stream finishes so new chats appear dynamically in the sidebar
213
+ useEffect(() => {
214
+ if (!isLoading && showHistory && mounted) {
215
+ fetchSessions();
216
+ }
217
+ }, [isLoading, showHistory, mounted, fetchSessions]);
218
+
135
219
  const [suggestions, setSuggestions] = useState<string[]>([]);
136
220
  const [isSuggesting, setIsSuggesting] = useState(false);
137
221
 
@@ -304,10 +388,20 @@ export function ChatWindow({
304
388
  }
305
389
  };
306
390
 
307
- const clearHistory = () => {
391
+ const clearHistory = async () => {
308
392
  clear();
309
393
  setSuggestions([]);
310
394
  setIsSuggesting(false);
395
+ if (activeSessionId) {
396
+ try {
397
+ await dbClearHistory(activeSessionId);
398
+ if (showHistory) {
399
+ fetchSessions();
400
+ }
401
+ } catch (e) {
402
+ console.error('[ChatWindow] Failed to clear remote history:', e);
403
+ }
404
+ }
311
405
  };
312
406
 
313
407
  const isEmpty = messages.length === 0;
@@ -362,23 +456,154 @@ export function ChatWindow({
362
456
  return (
363
457
  <div
364
458
  ref={windowRef}
365
- className={`relative flex flex-col h-full flex-1 border border-slate-200 dark:border-white/10 shadow-2xl transition-all duration-300 ${currentRadius} ${isGlass
459
+ className={`relative flex h-full flex-1 border border-slate-200 dark:border-white/10 shadow-2xl transition-all duration-300 ${currentRadius} ${isGlass
366
460
  ? 'bg-white/90 dark:bg-[#0f0f1a]/90 backdrop-blur-xl'
367
461
  : 'bg-white dark:bg-[#0f0f1a]'
368
462
  } ${className}`}
369
463
  style={{ '--primary': ui.primaryColor, '--accent': ui.accentColor, ...style } as React.CSSProperties}
370
464
  >
371
- {/* Resize Handle (Top-Left) */}
372
- {onResizeStart && (
373
- <div
374
- onMouseDown={onResizeStart}
375
- className="absolute top-0 left-0 w-6 h-6 cursor-nw-resize z-[100] group flex items-start justify-start p-1"
376
- title="Drag to resize"
377
- >
378
- <div className="w-2.5 h-2.5 border-t-2 border-l-2 border-slate-300 dark:border-white/20 group-hover:border-slate-500 dark:group-hover:border-white/50 transition-colors rounded-tl-[2px]" />
465
+ {/* Left History Sidebar */}
466
+ {showHistory && (
467
+ <div className="w-64 border-r border-slate-200 dark:border-white/10 bg-slate-50 dark:bg-[#131322] flex flex-col h-full shrink-0 select-none">
468
+ {/* Sidebar Header / New Chat */}
469
+ <div className="p-3 border-b border-slate-200 dark:border-white/10">
470
+ <button
471
+ onClick={() => {
472
+ const newId = `session_${Date.now()}`;
473
+ setInternalSessionId(newId);
474
+ setSessions(prev => [
475
+ { id: newId, title: `Chat Session ${prev.length + 1}`, lastMessageAt: new Date().toISOString() },
476
+ ...prev
477
+ ]);
478
+ }}
479
+ className="w-full flex items-center justify-center gap-1.5 py-2 px-3 bg-[var(--primary)] hover:opacity-90 text-white rounded-xl text-xs font-bold transition-all shadow-sm cursor-pointer"
480
+ >
481
+ <Plus className="w-3.5 h-3.5 stroke-[2.5]" />
482
+ New Chat
483
+ </button>
484
+ </div>
485
+
486
+ {/* Sessions List */}
487
+ <div className="flex-1 overflow-y-auto p-2 space-y-4 scrollbar-thin">
488
+ {sessions.length === 0 ? (
489
+ <div className="text-center text-slate-400 dark:text-white/20 text-xs py-8 font-medium">
490
+ No previous chats
491
+ </div>
492
+ ) : (
493
+ (() => {
494
+ const now = new Date();
495
+ const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
496
+ const startOfYesterday = new Date(startOfToday.getTime() - 24 * 60 * 60 * 1000);
497
+ const startOf7DaysAgo = new Date(startOfToday.getTime() - 7 * 24 * 60 * 60 * 1000);
498
+
499
+ const todayGroup: typeof sessions = [];
500
+ const yesterdayGroup: typeof sessions = [];
501
+ const previousGroup: typeof sessions = [];
502
+ const olderGroup: typeof sessions = [];
503
+
504
+ for (const s of sessions) {
505
+ const date = s.lastMessageAt ? new Date(s.lastMessageAt) : new Date();
506
+ if (date >= startOfToday) {
507
+ todayGroup.push(s);
508
+ } else if (date >= startOfYesterday) {
509
+ yesterdayGroup.push(s);
510
+ } else if (date >= startOf7DaysAgo) {
511
+ previousGroup.push(s);
512
+ } else {
513
+ olderGroup.push(s);
514
+ }
515
+ }
516
+
517
+ const renderGroup = (title: string, list: typeof sessions) => {
518
+ if (list.length === 0) return null;
519
+ return (
520
+ <div className="space-y-1.5">
521
+ <div className="flex items-center px-2 py-1 select-none">
522
+ <span className="text-[9px] font-black uppercase tracking-wider text-slate-400 dark:text-white/30">{title}</span>
523
+ <div className="flex-grow border-t border-slate-200 dark:border-white/10 ml-2" />
524
+ </div>
525
+ {list.map((s) => {
526
+ const isActive = s.id === activeSessionId;
527
+ const timeString = s.lastMessageAt
528
+ ? new Date(s.lastMessageAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
529
+ : '';
530
+
531
+ return (
532
+ <div
533
+ key={s.id}
534
+ className={`group relative flex items-center justify-between p-2 rounded-xl text-xs font-semibold transition-all ${
535
+ isActive
536
+ ? 'bg-slate-200/70 dark:bg-white/10 text-slate-900 dark:text-white'
537
+ : 'text-slate-500 hover:bg-slate-200/30 dark:hover:bg-white/5 hover:text-slate-800 dark:hover:text-slate-200'
538
+ }`}
539
+ >
540
+ <button
541
+ onClick={() => setInternalSessionId(s.id)}
542
+ className="flex-1 flex items-center gap-2 text-left min-w-0 pr-6 cursor-pointer"
543
+ >
544
+ <MessageSquare className="w-3.5 h-3.5 opacity-60 shrink-0 mt-0.5" />
545
+ <div className="truncate flex-1">
546
+ <div className="truncate leading-snug">{s.title || 'Conversation'}</div>
547
+ {timeString && (
548
+ <div className="text-[10px] text-slate-400 dark:text-white/30 font-medium mt-0.5">
549
+ {timeString}
550
+ </div>
551
+ )}
552
+ </div>
553
+ </button>
554
+
555
+ <button
556
+ onClick={async (e) => {
557
+ e.stopPropagation();
558
+ try {
559
+ await dbClearHistory(s.id);
560
+ setSessions(prev => prev.filter(x => x.id !== s.id));
561
+ if (activeSessionId === s.id) {
562
+ setInternalSessionId('default');
563
+ }
564
+ } catch (err) {
565
+ console.error('Failed to delete session:', err);
566
+ }
567
+ }}
568
+ title="Delete conversation"
569
+ className="absolute right-2 opacity-0 group-hover:opacity-100 hover:text-rose-500 dark:hover:text-rose-400 p-1 rounded-md hover:bg-slate-200 dark:hover:bg-white/10 transition-all cursor-pointer text-slate-400"
570
+ >
571
+ <Trash className="w-3.5 h-3.5" />
572
+ </button>
573
+ </div>
574
+ );
575
+ })}
576
+ </div>
577
+ );
578
+ };
579
+
580
+ return (
581
+ <>
582
+ {renderGroup('Today', todayGroup)}
583
+ {renderGroup('Yesterday', yesterdayGroup)}
584
+ {renderGroup('Previous 7 Days', previousGroup)}
585
+ {renderGroup('Older', olderGroup)}
586
+ </>
587
+ );
588
+ })()
589
+ )}
590
+ </div>
379
591
  </div>
380
592
  )}
381
- {/* ── Header ── */}
593
+
594
+ {/* Main Chat Viewport */}
595
+ <div className="relative flex flex-col h-full flex-1 min-w-0">
596
+ {/* Resize Handle (Top-Left) */}
597
+ {onResizeStart && (
598
+ <div
599
+ onMouseDown={onResizeStart}
600
+ className="absolute top-0 left-0 w-6 h-6 cursor-nw-resize z-[100] group flex items-start justify-start p-1"
601
+ title="Drag to resize"
602
+ >
603
+ <div className="w-2.5 h-2.5 border-t-2 border-l-2 border-slate-300 dark:border-white/20 group-hover:border-slate-500 dark:group-hover:border-white/50 transition-colors rounded-tl-[2px]" />
604
+ </div>
605
+ )}
606
+ {/* ── Header ── */}
382
607
  <div
383
608
  className="flex items-center justify-between px-5 py-4 border-b border-slate-200 dark:border-white/10"
384
609
  style={{ background: `linear-gradient(135deg, ${ui.primaryColor}15, ${ui.accentColor}10)` }}
@@ -521,21 +746,38 @@ export function ChatWindow({
521
746
  )}
522
747
  </div>
523
748
  </div>
524
- ) : (
525
- messages.map((msg, index) => (
526
- <MessageBubble
527
- key={msg.id}
528
- message={msg}
529
- sources={msg.sources}
530
- isStreaming={isLoading && index === messages.length - 1 && msg.role === 'assistant'}
531
- primaryColor={ui.primaryColor}
532
- accentColor={ui.accentColor}
533
- onAddToCart={onAddToCart}
534
- viewportSize={viewportSize}
535
- onFeedback={submitFeedback}
536
- />
537
- ))
538
- )}
749
+ ) : (() => {
750
+ let lastDayGroup = '';
751
+ return messages.map((msg, index) => {
752
+ const currentDayGroup = formatMessageDayLegend(msg.createdAt);
753
+ const showDaySeparator = currentDayGroup !== lastDayGroup;
754
+ lastDayGroup = currentDayGroup;
755
+
756
+ return (
757
+ <React.Fragment key={msg.id}>
758
+ {showDaySeparator && (
759
+ <div className="flex items-center my-6 select-none justify-center w-full">
760
+ <div className="flex-grow border-t border-slate-200 dark:border-white/10" />
761
+ <span className="mx-4 text-[9px] font-black text-slate-400 dark:text-zinc-500 uppercase tracking-widest bg-slate-100 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 px-3 py-1 rounded-full shrink-0">
762
+ {currentDayGroup}
763
+ </span>
764
+ <div className="flex-grow border-t border-slate-200 dark:border-white/10" />
765
+ </div>
766
+ )}
767
+ <MessageBubble
768
+ message={msg}
769
+ sources={msg.sources}
770
+ isStreaming={isLoading && index === messages.length - 1 && msg.role === 'assistant'}
771
+ primaryColor={ui.primaryColor}
772
+ accentColor={ui.accentColor}
773
+ onAddToCart={onAddToCart}
774
+ viewportSize={viewportSize}
775
+ onFeedback={submitFeedback}
776
+ />
777
+ </React.Fragment>
778
+ );
779
+ });
780
+ })()}
539
781
 
540
782
  {/* Typing indicator (only if assistant hasn't started replying yet) */}
541
783
  {isLoading && messages[messages.length - 1]?.role !== 'assistant' && (
@@ -679,6 +921,32 @@ export function ChatWindow({
679
921
  Press Enter to send · Shift+Enter for new line
680
922
  </p>
681
923
  </div>
924
+ </div>
682
925
  </div>
683
926
  );
684
927
  }
928
+
929
+ function formatMessageDayLegend(dateStr?: string | Date): string {
930
+ if (!dateStr) return 'Today';
931
+ try {
932
+ const d = new Date(dateStr);
933
+ const now = new Date();
934
+
935
+ // Check if today
936
+ if (d.toDateString() === now.toDateString()) {
937
+ return 'Today';
938
+ }
939
+
940
+ // Check if yesterday
941
+ const yesterday = new Date(now);
942
+ yesterday.setDate(now.getDate() - 1);
943
+ if (d.toDateString() === yesterday.toDateString()) {
944
+ return 'Yesterday';
945
+ }
946
+
947
+ // Otherwise return formatted date
948
+ return d.toLocaleDateString([], { weekday: 'long', month: 'short', day: 'numeric' });
949
+ } catch {
950
+ return 'Today';
951
+ }
952
+ }
@@ -38,7 +38,16 @@ export function ConfigProvider({
38
38
  const headersInput = config?.headers;
39
39
  const retrivoraApiBaseInput = config?.retrivoraApiBase;
40
40
  const embeddingInput = config?.embedding;
41
- const uiInput = config?.ui;
41
+ const uiInput = useMemo(() => {
42
+ const flatUi: Partial<UIConfig> = {};
43
+ if (config?.primaryColor) flatUi.primaryColor = config.primaryColor;
44
+ if (config?.secondaryColor) flatUi.accentColor = config.secondaryColor;
45
+ if (config?.accentColor) flatUi.accentColor = config.accentColor;
46
+ if (config?.theme) flatUi.theme = config.theme;
47
+ if (config?.borderRadius) flatUi.borderRadius = config.borderRadius;
48
+ if (config?.visualStyle) flatUi.visualStyle = config.visualStyle;
49
+ return { ...flatUi, ...config?.ui };
50
+ }, [config]);
42
51
  const explicitSettings = useMemo(
43
52
  () => projectSettingsInput
44
53
  ? normalizeProjectSettings(projectId, projectSettingsInput)
@@ -38,15 +38,15 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
38
38
  namespaceUsed: string;
39
39
  } | null>(null);
40
40
 
41
- const resolvedLicenseKey = licenseKey ||
42
- configHeaders?.['x-license-key'] ||
43
- configHeaders?.['X-License-Key'] ||
44
- configHeaders?.['authorization']?.replace(/^Bearer\s+/i, '') ||
41
+ const resolvedLicenseKey = licenseKey ||
42
+ configHeaders?.['x-license-key'] ||
43
+ configHeaders?.['X-License-Key'] ||
44
+ configHeaders?.['authorization']?.replace(/^Bearer\s+/i, '') ||
45
45
  configHeaders?.['Authorization']?.replace(/^Bearer\s+/i, '');
46
46
 
47
47
  const licenseTier = decodeLicenseTier(resolvedLicenseKey);
48
- const isFreeTier = !projectId ||
49
- projectId.includes('free') ||
48
+ const isFreeTier = !projectId ||
49
+ projectId.includes('free') ||
50
50
  projectId.includes('demo') ||
51
51
  ['free_trial', 'free_tier', 'free', 'hobby'].includes(licenseTier.toLowerCase());
52
52
 
@@ -59,14 +59,14 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
59
59
  const COMMON_DIMENSIONS = [64, 128, 256, 384, 512, 768, 1024, 1536, 3072];
60
60
  const currentModel = embedding?.model || 'unknown';
61
61
  const defaultDimension = isFreeTier ? 768 : (embedding?.dimensions || 1536);
62
-
62
+
63
63
  let availableDimensions = isFreeTier
64
64
  ? [768]
65
65
  : Object.entries(MULTI_DIMENSION_MODELS).find(([k]) => currentModel.includes(k))?.[1];
66
66
 
67
67
  if (!availableDimensions) {
68
- availableDimensions = COMMON_DIMENSIONS.includes(defaultDimension)
69
- ? COMMON_DIMENSIONS
68
+ availableDimensions = COMMON_DIMENSIONS.includes(defaultDimension)
69
+ ? COMMON_DIMENSIONS
70
70
  : [...COMMON_DIMENSIONS, defaultDimension].sort((a, b) => a - b);
71
71
  }
72
72
 
@@ -123,7 +123,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
123
123
  ...(licenseKey ? { 'x-license-key': licenseKey } : {}),
124
124
  };
125
125
 
126
- console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
126
+ //console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
127
127
 
128
128
  try {
129
129
  let response = await fetch(primaryUrl, {
@@ -145,7 +145,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
145
145
 
146
146
  if (!response.ok) throw new Error(result.error || `Upload failed with HTTP status ${response.status}`);
147
147
 
148
- console.log(`[Retrivora SDK] ✅ Upload response success:`, result);
148
+ //console.log(`[Retrivora SDK] ✅ Upload response success:`, result);
149
149
 
150
150
  setFileStates(prev => prev.map(s => s.status === 'uploading' ? { ...s, status: 'success' } : s));
151
151
 
@@ -170,18 +170,17 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
170
170
 
171
171
  return (
172
172
  <>
173
- <div
174
- className={`p-6 border-2 border-dashed transition-all duration-300 rounded-2xl ${
175
- isDragging
176
- ? 'border-emerald-500 bg-emerald-50/50 dark:bg-emerald-500/5'
173
+ <div
174
+ className={`p-6 border-2 border-dashed transition-all duration-300 rounded-2xl ${isDragging
175
+ ? 'border-emerald-500 bg-emerald-50/50 dark:bg-emerald-500/5'
177
176
  : 'border-slate-200 dark:border-white/10 bg-white dark:bg-white/5'
178
- } ${className}`}
177
+ } ${className}`}
179
178
  onDragOver={onDragOver}
180
179
  onDragLeave={onDragLeave}
181
180
  onDrop={onDrop}
182
181
  >
183
182
  <div className="flex flex-col items-center justify-center text-center">
184
- <div
183
+ <div
185
184
  className="w-12 h-12 rounded-full flex items-center justify-center mb-4 shadow-sm"
186
185
  style={{ background: `linear-gradient(135deg, ${ui.primaryColor}20, ${ui.accentColor}20)` }}
187
186
  >
@@ -196,7 +195,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
196
195
  onClick={() => fileInputRef.current?.click()}
197
196
  disabled={isUploading}
198
197
  className="px-4 py-2 rounded-lg text-sm font-medium transition-all hover:scale-105 active:scale-95 disabled:opacity-50"
199
- style={{
198
+ style={{
200
199
  backgroundColor: `${ui.primaryColor}15`,
201
200
  color: ui.primaryColor,
202
201
  border: `1px solid ${ui.primaryColor}30`
@@ -204,12 +203,12 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
204
203
  >
205
204
  Select Files
206
205
  </button>
207
- <input
206
+ <input
208
207
  ref={fileInputRef}
209
- type="file"
210
- multiple
211
- onChange={onFileSelect}
212
- className="hidden"
208
+ type="file"
209
+ multiple
210
+ onChange={onFileSelect}
211
+ className="hidden"
213
212
  accept=".pdf,.docx,.doc,.xlsx,.xls,.csv,.txt,.md,.json"
214
213
  />
215
214
 
@@ -222,9 +221,9 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
222
221
  className="px-3 py-1.5 rounded-lg bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 text-slate-800 dark:text-white/90 outline-none focus:border-emerald-500 transition-colors text-sm font-medium cursor-pointer"
223
222
  >
224
223
  {availableDimensions.map(dim => (
225
- <option
226
- key={dim}
227
- value={dim}
224
+ <option
225
+ key={dim}
226
+ value={dim}
228
227
  className="bg-white dark:bg-slate-900 text-slate-800 dark:text-white"
229
228
  >
230
229
  {dim}
@@ -237,7 +236,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
237
236
  {fileStates.length > 0 && (
238
237
  <div className="mt-8 space-y-3">
239
238
  {fileStates.map((state, i) => (
240
- <div
239
+ <div
241
240
  key={i}
242
241
  className="flex items-center justify-between p-3 rounded-xl bg-slate-50 dark:bg-white/5 border border-slate-100 dark:border-white/10"
243
242
  >
@@ -263,9 +262,9 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
263
262
  <AlertCircle className="w-4 h-4 text-rose-500" />
264
263
  </div>
265
264
  )}
266
-
265
+
267
266
  {state.status !== 'uploading' && (
268
- <button
267
+ <button
269
268
  onClick={() => removeFile(i)}
270
269
  className="p-1 rounded-md hover:bg-slate-200 dark:hover:bg-white/10 transition-colors"
271
270
  >