@retrivora-ai/rag-engine 1.2.1 → 1.2.3

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 (50) hide show
  1. package/dist/DocumentChunker-BXOUMKoP.d.ts +93 -0
  2. package/dist/DocumentChunker-D1dg5iCi.d.mts +93 -0
  3. package/dist/{chunk-GCPPRD2G.mjs → chunk-WGPNEAK3.mjs} +37 -3
  4. package/dist/handlers/index.d.mts +2 -2
  5. package/dist/handlers/index.d.ts +2 -2
  6. package/dist/handlers/index.js +37 -3
  7. package/dist/handlers/index.mjs +1 -1
  8. package/dist/{index-DbtE8wLM.d.ts → index-B67KQ9NN.d.ts} +1 -1
  9. package/dist/{RagConfig-BOLOz0_O.d.mts → index-Cti1u0y1.d.mts} +86 -94
  10. package/dist/{RagConfig-BOLOz0_O.d.ts → index-Cti1u0y1.d.ts} +86 -94
  11. package/dist/{index-64BDupW3.d.mts → index-kUXnRvuI.d.mts} +1 -1
  12. package/dist/index.d.mts +52 -78
  13. package/dist/index.d.ts +52 -78
  14. package/dist/index.js +313 -124
  15. package/dist/index.mjs +293 -97
  16. package/dist/server.d.mts +5 -4
  17. package/dist/server.d.ts +5 -4
  18. package/dist/server.js +37 -3
  19. package/dist/server.mjs +1 -1
  20. package/package.json +2 -1
  21. package/src/components/ChatWidget.tsx +1 -8
  22. package/src/components/ChatWindow.tsx +120 -29
  23. package/src/components/ConfigProvider.tsx +7 -33
  24. package/src/components/DocumentUpload.tsx +1 -8
  25. package/src/components/DynamicChart.tsx +113 -0
  26. package/src/components/MessageBubble.tsx +51 -13
  27. package/src/components/ProductCard.tsx +1 -7
  28. package/src/components/ProductCarousel.tsx +1 -7
  29. package/src/components/SourceCard.tsx +1 -6
  30. package/src/config/RagConfig.ts +2 -0
  31. package/src/config/uiConstants.ts +23 -0
  32. package/src/core/LangChainAgent.ts +20 -2
  33. package/src/core/Pipeline.ts +19 -1
  34. package/src/core/VectorPlugin.ts +1 -1
  35. package/src/handlers/index.ts +1 -1
  36. package/src/hooks/useRagChat.ts +1 -45
  37. package/src/hooks/useStoredMessages.ts +1 -1
  38. package/src/index.ts +20 -5
  39. package/src/llm/ILLMProvider.ts +1 -13
  40. package/src/llm/providers/AnthropicProvider.ts +2 -1
  41. package/src/llm/providers/GeminiProvider.ts +2 -1
  42. package/src/llm/providers/OllamaProvider.ts +2 -1
  43. package/src/llm/providers/OpenAIProvider.ts +2 -1
  44. package/src/llm/providers/UniversalLLMAdapter.ts +2 -1
  45. package/src/server.ts +2 -2
  46. package/src/types/chat.ts +53 -0
  47. package/src/types/index.ts +3 -0
  48. package/src/types/props.ts +79 -0
  49. package/dist/DocumentChunker-Dh9TvmGG.d.mts +0 -45
  50. package/dist/DocumentChunker-Dh9TvmGG.d.ts +0 -45
@@ -0,0 +1,93 @@
1
+ import { C as ChatMessage, c as ChatOptions } from './index-Cti1u0y1.js';
2
+
3
+ /**
4
+ * Generic LLM Provider interface.
5
+ * Covers both chat completion and embedding generation so a single
6
+ * provider can handle both responsibilities when appropriate.
7
+ */
8
+
9
+ interface EmbedOptions {
10
+ /** Override model for this specific embed call */
11
+ model?: string;
12
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
13
+ taskType?: 'query' | 'document';
14
+ }
15
+ interface ILLMProvider {
16
+ /**
17
+ * Send a chat completion request.
18
+ * @param messages – the full conversation history
19
+ * @param context – retrieved RAG context to inject
20
+ * @param options – optional per-call overrides
21
+ * @returns – the assistant's reply text
22
+ */
23
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
24
+ /**
25
+ * Send a streaming chat completion request.
26
+ * @returns – an async iterable of text chunks
27
+ */
28
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
29
+ /**
30
+ * Generate an embedding vector for the given text.
31
+ * @param text – text to embed
32
+ * @param options – optional overrides
33
+ * @returns – float array (the embedding)
34
+ */
35
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
36
+ /**
37
+ * Generate embedding vectors for multiple texts in a single batch.
38
+ * @param texts – array of texts to embed
39
+ * @param options – optional overrides
40
+ * @returns – array of float arrays
41
+ */
42
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
43
+ /**
44
+ * Check if the provider endpoint is reachable.
45
+ */
46
+ ping(): Promise<boolean>;
47
+ }
48
+
49
+ /**
50
+ * DocumentChunker — splits long text into overlapping chunks
51
+ * suitable for vector embedding and retrieval.
52
+ *
53
+ * Strategy: sentence-aware sliding window
54
+ * 1. Split on sentence boundaries
55
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
56
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
57
+ */
58
+ interface Chunk {
59
+ id: string;
60
+ content: string;
61
+ metadata?: Record<string, unknown>;
62
+ }
63
+ interface ChunkOptions {
64
+ /** Target chunk size in characters (default 1000) */
65
+ chunkSize?: number;
66
+ /** Overlap between consecutive chunks in characters (default 200) */
67
+ chunkOverlap?: number;
68
+ /** Source document identifier used as ID prefix */
69
+ docId?: string | number;
70
+ /** Extra metadata to attach to every chunk */
71
+ metadata?: Record<string, unknown>;
72
+ /** Characters used to split text, in order of priority */
73
+ separators?: string[];
74
+ }
75
+ declare class DocumentChunker {
76
+ private readonly chunkSize;
77
+ private readonly chunkOverlap;
78
+ private readonly separators;
79
+ constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
80
+ /**
81
+ * Split a single text string into overlapping chunks using a recursive strategy.
82
+ * Preserves structural boundaries (Markdown headers) where possible.
83
+ */
84
+ chunk(text: string, options?: ChunkOptions): Chunk[];
85
+ private recursiveSplit;
86
+ chunkMany(documents: Array<{
87
+ content: string;
88
+ docId?: string | number;
89
+ metadata?: Record<string, unknown>;
90
+ }>): Chunk[];
91
+ }
92
+
93
+ export { type Chunk as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChunkOptions as a };
@@ -0,0 +1,93 @@
1
+ import { C as ChatMessage, c as ChatOptions } from './index-Cti1u0y1.mjs';
2
+
3
+ /**
4
+ * Generic LLM Provider interface.
5
+ * Covers both chat completion and embedding generation so a single
6
+ * provider can handle both responsibilities when appropriate.
7
+ */
8
+
9
+ interface EmbedOptions {
10
+ /** Override model for this specific embed call */
11
+ model?: string;
12
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
13
+ taskType?: 'query' | 'document';
14
+ }
15
+ interface ILLMProvider {
16
+ /**
17
+ * Send a chat completion request.
18
+ * @param messages – the full conversation history
19
+ * @param context – retrieved RAG context to inject
20
+ * @param options – optional per-call overrides
21
+ * @returns – the assistant's reply text
22
+ */
23
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
24
+ /**
25
+ * Send a streaming chat completion request.
26
+ * @returns – an async iterable of text chunks
27
+ */
28
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
29
+ /**
30
+ * Generate an embedding vector for the given text.
31
+ * @param text – text to embed
32
+ * @param options – optional overrides
33
+ * @returns – float array (the embedding)
34
+ */
35
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
36
+ /**
37
+ * Generate embedding vectors for multiple texts in a single batch.
38
+ * @param texts – array of texts to embed
39
+ * @param options – optional overrides
40
+ * @returns – array of float arrays
41
+ */
42
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
43
+ /**
44
+ * Check if the provider endpoint is reachable.
45
+ */
46
+ ping(): Promise<boolean>;
47
+ }
48
+
49
+ /**
50
+ * DocumentChunker — splits long text into overlapping chunks
51
+ * suitable for vector embedding and retrieval.
52
+ *
53
+ * Strategy: sentence-aware sliding window
54
+ * 1. Split on sentence boundaries
55
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
56
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
57
+ */
58
+ interface Chunk {
59
+ id: string;
60
+ content: string;
61
+ metadata?: Record<string, unknown>;
62
+ }
63
+ interface ChunkOptions {
64
+ /** Target chunk size in characters (default 1000) */
65
+ chunkSize?: number;
66
+ /** Overlap between consecutive chunks in characters (default 200) */
67
+ chunkOverlap?: number;
68
+ /** Source document identifier used as ID prefix */
69
+ docId?: string | number;
70
+ /** Extra metadata to attach to every chunk */
71
+ metadata?: Record<string, unknown>;
72
+ /** Characters used to split text, in order of priority */
73
+ separators?: string[];
74
+ }
75
+ declare class DocumentChunker {
76
+ private readonly chunkSize;
77
+ private readonly chunkOverlap;
78
+ private readonly separators;
79
+ constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
80
+ /**
81
+ * Split a single text string into overlapping chunks using a recursive strategy.
82
+ * Preserves structural boundaries (Markdown headers) where possible.
83
+ */
84
+ chunk(text: string, options?: ChunkOptions): Chunk[];
85
+ private recursiveSplit;
86
+ chunkMany(documents: Array<{
87
+ content: string;
88
+ docId?: string | number;
89
+ metadata?: Record<string, unknown>;
90
+ }>): Chunk[];
91
+ }
92
+
93
+ export { type Chunk as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChunkOptions as a };
@@ -1692,11 +1692,29 @@ Sources Used: ${JSON.stringify(
1692
1692
  )}`;
1693
1693
  }
1694
1694
  });
1695
+ const defaultAgentPrompt = "You are a helpful AI assistant with access to a document search tool.";
1696
+ let finalSystemPrompt = this.config.llm.systemPrompt || defaultAgentPrompt;
1697
+ const chartInstruction = `
1698
+
1699
+ When presenting structured data, statistics, or comparisons, decide if it is best presented as a table or a chart.
1700
+ - For tables: use standard Markdown tables.
1701
+ - For charts (bar, line, pie): Output a JSON code block with language 'chart' matching this schema:
1702
+ \`\`\`chart
1703
+ {
1704
+ "type": "bar" | "line" | "pie",
1705
+ "xAxisKey": "name",
1706
+ "dataKeys": ["value"],
1707
+ "data": [{"name": "A", "value": 10}]
1708
+ }
1709
+ \`\`\``;
1710
+ if (!finalSystemPrompt.includes("chart")) {
1711
+ finalSystemPrompt += chartInstruction;
1712
+ }
1695
1713
  this.agent = createAgent({
1696
1714
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1697
1715
  model: chatModel,
1698
1716
  tools: [searchTool],
1699
- systemPrompt: this.config.llm.systemPrompt || "You are a helpful AI assistant with access to a document search tool."
1717
+ systemPrompt: finalSystemPrompt
1700
1718
  });
1701
1719
  void HumanMessage;
1702
1720
  } catch (error) {
@@ -2231,8 +2249,24 @@ var Pipeline = class {
2231
2249
  this.reranker = new Reranker();
2232
2250
  }
2233
2251
  async initialize() {
2234
- var _a;
2252
+ var _a, _b;
2235
2253
  if (this.initialised) return;
2254
+ const chartInstruction = `
2255
+
2256
+ When presenting structured data, statistics, or comparisons, decide if it is best presented as a table or a chart.
2257
+ - For tables: use standard Markdown tables.
2258
+ - For charts (bar, line, pie): Output a JSON code block with language 'chart' matching this schema:
2259
+ \`\`\`chart
2260
+ {
2261
+ "type": "bar" | "line" | "pie",
2262
+ "xAxisKey": "name",
2263
+ "dataKeys": ["value"],
2264
+ "data": [{"name": "A", "value": 10}]
2265
+ }
2266
+ \`\`\``;
2267
+ if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes("chart"))) {
2268
+ this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
2269
+ }
2236
2270
  console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
2237
2271
  this.vectorDB = await ProviderRegistry.createVectorProvider(this.config.vectorDb);
2238
2272
  const { llmProvider, embeddingProvider } = await EmbeddingStrategyResolver.resolve(
@@ -2247,7 +2281,7 @@ var Pipeline = class {
2247
2281
  this.entityExtractor = new EntityExtractor(this.llmProvider);
2248
2282
  }
2249
2283
  await this.vectorDB.initialize();
2250
- if (((_a = this.config.rag) == null ? void 0 : _a.architecture) === "agentic") {
2284
+ if (((_b = this.config.rag) == null ? void 0 : _b.architecture) === "agentic") {
2251
2285
  this.agent = new LangChainAgent(this, this.config);
2252
2286
  await this.agent.initialize(this.llmProvider);
2253
2287
  }
@@ -1,3 +1,3 @@
1
- import '../RagConfig-BOLOz0_O.mjs';
2
- export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-64BDupW3.mjs';
1
+ import '../index-Cti1u0y1.mjs';
2
+ export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-kUXnRvuI.mjs';
3
3
  import 'next/server';
@@ -1,3 +1,3 @@
1
- import '../RagConfig-BOLOz0_O.js';
2
- export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-DbtE8wLM.js';
1
+ import '../index-Cti1u0y1.js';
2
+ export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-B67KQ9NN.js';
3
3
  import 'next/server';
@@ -3261,11 +3261,29 @@ Sources Used: ${JSON.stringify(
3261
3261
  )}`;
3262
3262
  }
3263
3263
  });
3264
+ const defaultAgentPrompt = "You are a helpful AI assistant with access to a document search tool.";
3265
+ let finalSystemPrompt = this.config.llm.systemPrompt || defaultAgentPrompt;
3266
+ const chartInstruction = `
3267
+
3268
+ When presenting structured data, statistics, or comparisons, decide if it is best presented as a table or a chart.
3269
+ - For tables: use standard Markdown tables.
3270
+ - For charts (bar, line, pie): Output a JSON code block with language 'chart' matching this schema:
3271
+ \`\`\`chart
3272
+ {
3273
+ "type": "bar" | "line" | "pie",
3274
+ "xAxisKey": "name",
3275
+ "dataKeys": ["value"],
3276
+ "data": [{"name": "A", "value": 10}]
3277
+ }
3278
+ \`\`\``;
3279
+ if (!finalSystemPrompt.includes("chart")) {
3280
+ finalSystemPrompt += chartInstruction;
3281
+ }
3264
3282
  this.agent = createAgent({
3265
3283
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3266
3284
  model: chatModel,
3267
3285
  tools: [searchTool],
3268
- systemPrompt: this.config.llm.systemPrompt || "You are a helpful AI assistant with access to a document search tool."
3286
+ systemPrompt: finalSystemPrompt
3269
3287
  });
3270
3288
  void HumanMessage;
3271
3289
  } catch (error) {
@@ -3794,8 +3812,24 @@ var Pipeline = class {
3794
3812
  this.reranker = new Reranker();
3795
3813
  }
3796
3814
  async initialize() {
3797
- var _a;
3815
+ var _a, _b;
3798
3816
  if (this.initialised) return;
3817
+ const chartInstruction = `
3818
+
3819
+ When presenting structured data, statistics, or comparisons, decide if it is best presented as a table or a chart.
3820
+ - For tables: use standard Markdown tables.
3821
+ - For charts (bar, line, pie): Output a JSON code block with language 'chart' matching this schema:
3822
+ \`\`\`chart
3823
+ {
3824
+ "type": "bar" | "line" | "pie",
3825
+ "xAxisKey": "name",
3826
+ "dataKeys": ["value"],
3827
+ "data": [{"name": "A", "value": 10}]
3828
+ }
3829
+ \`\`\``;
3830
+ if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes("chart"))) {
3831
+ this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3832
+ }
3799
3833
  console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
3800
3834
  this.vectorDB = await ProviderRegistry.createVectorProvider(this.config.vectorDb);
3801
3835
  const { llmProvider, embeddingProvider } = await EmbeddingStrategyResolver.resolve(
@@ -3810,7 +3844,7 @@ var Pipeline = class {
3810
3844
  this.entityExtractor = new EntityExtractor(this.llmProvider);
3811
3845
  }
3812
3846
  await this.vectorDB.initialize();
3813
- if (((_a = this.config.rag) == null ? void 0 : _a.architecture) === "agentic") {
3847
+ if (((_b = this.config.rag) == null ? void 0 : _b.architecture) === "agentic") {
3814
3848
  this.agent = new LangChainAgent(this, this.config);
3815
3849
  await this.agent.initialize(this.llmProvider);
3816
3850
  }
@@ -9,7 +9,7 @@ import {
9
9
  sseFrame,
10
10
  sseMetaFrame,
11
11
  sseTextFrame
12
- } from "../chunk-GCPPRD2G.mjs";
12
+ } from "../chunk-WGPNEAK3.mjs";
13
13
  import "../chunk-YLTMFW4M.mjs";
14
14
  import "../chunk-X4TOT24V.mjs";
15
15
  export {
@@ -1,4 +1,4 @@
1
- import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-BOLOz0_O.js';
1
+ import { h as RagConfig, C as ChatMessage, d as ChatResponse, I as IngestDocument } from './index-Cti1u0y1.js';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  interface ValidationError {
@@ -1,62 +1,12 @@
1
- interface VectorMatch {
2
- id: string | number;
3
- score: number;
4
- content: string;
5
- metadata?: Record<string, unknown>;
6
- }
7
- interface UpsertDocument {
8
- id: string | number;
9
- vector: number[];
1
+ type MessageRole = 'user' | 'assistant' | 'system';
2
+ interface ChatMessage {
3
+ role: MessageRole;
10
4
  content: string;
11
- metadata?: Record<string, unknown>;
12
5
  }
13
- interface IngestDocument {
14
- docId: string | number;
15
- content: string;
16
- metadata?: Record<string, unknown>;
17
- }
18
- interface ChatResponse {
19
- reply: string;
20
- sources: VectorMatch[];
21
- graphData?: GraphSearchResult;
22
- }
23
- interface GraphNode {
6
+ interface RagMessage extends ChatMessage {
24
7
  id: string;
25
- label: string;
26
- properties?: Record<string, unknown>;
27
- }
28
- interface Edge {
29
- source: string;
30
- target: string;
31
- type: string;
32
- properties?: Record<string, unknown>;
33
- }
34
- interface GraphSearchResult {
35
- nodes: GraphNode[];
36
- edges: Edge[];
37
- }
38
- interface RetrievalResult {
39
- sources: VectorMatch[];
40
- graphData?: GraphSearchResult;
41
- }
42
- interface Product {
43
- id: string | number;
44
- name: string;
45
- brand?: string;
46
- price?: string | number;
47
- image?: string;
48
- link?: string;
49
- description?: string;
50
- }
51
-
52
- /**
53
- * Generic LLM Provider interface.
54
- * Covers both chat completion and embedding generation so a single
55
- * provider can handle both responsibilities when appropriate.
56
- */
57
- interface ChatMessage {
58
- role: 'user' | 'assistant' | 'system';
59
- content: string;
8
+ sources?: VectorMatch[];
9
+ createdAt: string;
60
10
  }
61
11
  interface ChatOptions {
62
12
  /** Override max tokens for this specific call */
@@ -66,44 +16,33 @@ interface ChatOptions {
66
16
  /** Stop sequences */
67
17
  stop?: string[];
68
18
  }
69
- interface EmbedOptions {
70
- /** Override model for this specific embed call */
71
- model?: string;
72
- /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
73
- taskType?: 'query' | 'document';
19
+ interface UseRagChatOptions {
20
+ /** Override the chat API endpoint (default: /api/chat) */
21
+ apiUrl?: string;
22
+ /** Override project namespace */
23
+ namespace?: string;
24
+ /** Persist chat history to localStorage (default: true) */
25
+ persist?: boolean;
26
+ /** Called after each successful assistant reply */
27
+ onReply?: (message: RagMessage) => void;
28
+ /** Called on error */
29
+ onError?: (error: string) => void;
74
30
  }
75
- interface ILLMProvider {
76
- /**
77
- * Send a chat completion request.
78
- * @param messages the full conversation history
79
- * @param context – retrieved RAG context to inject
80
- * @param options – optional per-call overrides
81
- * @returns – the assistant's reply text
82
- */
83
- chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
84
- /**
85
- * Send a streaming chat completion request.
86
- * @returns an async iterable of text chunks
87
- */
88
- chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
89
- /**
90
- * Generate an embedding vector for the given text.
91
- * @param text – text to embed
92
- * @param options – optional overrides
93
- * @returns – float array (the embedding)
94
- */
95
- embed(text: string, options?: EmbedOptions): Promise<number[]>;
96
- /**
97
- * Generate embedding vectors for multiple texts in a single batch.
98
- * @param texts – array of texts to embed
99
- * @param options – optional overrides
100
- * @returns – array of float arrays
101
- */
102
- batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
103
- /**
104
- * Check if the provider endpoint is reachable.
105
- */
106
- ping(): Promise<boolean>;
31
+ interface UseRagChatReturn {
32
+ /** All messages in the current conversation */
33
+ messages: RagMessage[];
34
+ /** Whether a response is in flight */
35
+ isLoading: boolean;
36
+ /** Current error message, or null */
37
+ error: string | null;
38
+ /** Send a user message */
39
+ send: (text: string) => Promise<void>;
40
+ /** Clear the conversation (and localStorage if persist=true) */
41
+ clear: () => void;
42
+ /** Retry the last failed send */
43
+ retry: () => Promise<void>;
44
+ /** Programmatically set the conversation (e.g. to restore from a DB) */
45
+ setMessages: React.Dispatch<React.SetStateAction<RagMessage[]>>;
107
46
  }
108
47
 
109
48
  /**
@@ -233,6 +172,8 @@ interface UIConfig {
233
172
  allowUpload?: boolean;
234
173
  /** Whether to allow manual resizing of the chat window. Defaults to true. */
235
174
  allowResize?: boolean;
175
+ /** Whether to enable voice search input. Defaults to true. */
176
+ enableVoiceInput?: boolean;
236
177
  }
237
178
  interface RAGConfig {
238
179
  /** Number of top-K chunks retrieved per query */
@@ -280,4 +221,55 @@ interface RagConfig {
280
221
  graphDb?: GraphDBConfig;
281
222
  }
282
223
 
283
- export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
224
+ interface VectorMatch {
225
+ id: string | number;
226
+ score: number;
227
+ content: string;
228
+ metadata?: Record<string, unknown>;
229
+ }
230
+ interface UpsertDocument {
231
+ id: string | number;
232
+ vector: number[];
233
+ content: string;
234
+ metadata?: Record<string, unknown>;
235
+ }
236
+ interface IngestDocument {
237
+ docId: string | number;
238
+ content: string;
239
+ metadata?: Record<string, unknown>;
240
+ }
241
+ interface ChatResponse {
242
+ reply: string;
243
+ sources: VectorMatch[];
244
+ graphData?: GraphSearchResult;
245
+ }
246
+ interface GraphNode {
247
+ id: string;
248
+ label: string;
249
+ properties?: Record<string, unknown>;
250
+ }
251
+ interface Edge {
252
+ source: string;
253
+ target: string;
254
+ type: string;
255
+ properties?: Record<string, unknown>;
256
+ }
257
+ interface GraphSearchResult {
258
+ nodes: GraphNode[];
259
+ edges: Edge[];
260
+ }
261
+ interface RetrievalResult {
262
+ sources: VectorMatch[];
263
+ graphData?: GraphSearchResult;
264
+ }
265
+ interface Product {
266
+ id: string | number;
267
+ name: string;
268
+ brand?: string;
269
+ price?: string | number;
270
+ image?: string;
271
+ link?: string;
272
+ description?: string;
273
+ }
274
+
275
+ export type { ChatMessage as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, Product as P, RagMessage as R, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingProvider as e, LLMProvider as f, RAGConfig as g, RagConfig as h, UpsertDocument as i, VectorDBConfig as j, VectorDBProvider as k, RetrievalResult as l, GraphNode as m, Edge as n, GraphSearchResult as o };