@retrivora-ai/rag-engine 1.0.4 → 1.0.5

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 (39) hide show
  1. package/dist/DocumentChunker-Dh9TvmGG.d.mts +45 -0
  2. package/dist/DocumentChunker-Dh9TvmGG.d.ts +45 -0
  3. package/dist/{RagConfig-DRJO4hGU.d.mts → RagConfig-BEmz4hVP.d.mts} +58 -1
  4. package/dist/{RagConfig-DRJO4hGU.d.ts → RagConfig-BEmz4hVP.d.ts} +58 -1
  5. package/dist/{chunk-6MLZHQZT.mjs → chunk-MWL4AGQI.mjs} +189 -98
  6. package/dist/handlers/index.d.mts +2 -2
  7. package/dist/handlers/index.d.ts +2 -2
  8. package/dist/handlers/index.js +191 -100
  9. package/dist/handlers/index.mjs +11 -3
  10. package/dist/index-CSfaCeux.d.ts +206 -0
  11. package/dist/index-DFSy0CG6.d.mts +206 -0
  12. package/dist/index.d.mts +3 -4
  13. package/dist/index.d.ts +3 -4
  14. package/dist/index.js +103 -89
  15. package/dist/index.mjs +91 -95
  16. package/dist/server.d.mts +45 -97
  17. package/dist/server.d.ts +45 -97
  18. package/dist/server.js +271 -215
  19. package/dist/server.mjs +78 -167
  20. package/package.json +12 -10
  21. package/src/components/ChatWindow.tsx +2 -2
  22. package/src/components/ConfigProvider.tsx +2 -2
  23. package/src/components/MessageBubble.tsx +2 -2
  24. package/src/components/SourceCard.tsx +1 -1
  25. package/src/components/ThemeToggle.tsx +1 -1
  26. package/src/config/ConfigBuilder.ts +86 -211
  27. package/src/config/uiConstants.ts +23 -0
  28. package/src/core/ConfigResolver.ts +57 -29
  29. package/src/core/LangChainAgent.ts +73 -40
  30. package/src/core/Pipeline.ts +63 -7
  31. package/src/core/ProviderRegistry.ts +2 -2
  32. package/src/core/QueryProcessor.ts +9 -8
  33. package/src/handlers/index.ts +138 -49
  34. package/src/hooks/useRagChat.ts +71 -32
  35. package/src/server.ts +12 -2
  36. package/dist/DocumentChunker-C-sCZPhi.d.mts +0 -102
  37. package/dist/DocumentChunker-C-sCZPhi.d.ts +0 -102
  38. package/dist/index-B2mutkgp.d.ts +0 -116
  39. package/dist/index-Bjy0es5a.d.mts +0 -116
@@ -0,0 +1,206 @@
1
+ import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-BEmz4hVP.mjs';
2
+ import { NextRequest, NextResponse } from 'next/server';
3
+
4
+ interface ValidationError {
5
+ field: string;
6
+ message: string;
7
+ suggestion?: string;
8
+ severity: 'error' | 'warning';
9
+ }
10
+ /**
11
+ * ConfigValidator.ts — Comprehensive configuration validation.
12
+ * Uses a pluggable architecture to delegate provider-specific checks.
13
+ */
14
+ declare class ConfigValidator {
15
+ /**
16
+ * Validates the entire RagConfig object.
17
+ */
18
+ static validate(config: RagConfig): Promise<ValidationError[]>;
19
+ private static validateVectorDbConfig;
20
+ private static validateLLMConfig;
21
+ private static validateEmbeddingConfig;
22
+ /**
23
+ * Temporary fallbacks for providers not yet migrated to the pluggable architecture.
24
+ */
25
+ private static fallbackVectorValidation;
26
+ private static fallbackLLMValidation;
27
+ private static fallbackEmbeddingValidation;
28
+ private static validateUIConfig;
29
+ private static validateRAGConfig;
30
+ private static isValidCSSColor;
31
+ static validateAndThrow(config: RagConfig): Promise<void>;
32
+ }
33
+
34
+ /**
35
+ * Interface for provider-specific configuration validation logic.
36
+ */
37
+ interface IProviderValidator {
38
+ /**
39
+ * Validates the configuration for a specific provider.
40
+ * @param config - The configuration object to validate.
41
+ * @returns An array of validation errors (empty if valid).
42
+ */
43
+ validate(config: Record<string, unknown>): ValidationError[];
44
+ }
45
+ /**
46
+ * Result of a provider health check.
47
+ */
48
+ interface HealthCheckResult {
49
+ healthy: boolean;
50
+ provider: string;
51
+ version?: string;
52
+ capabilities?: Record<string, unknown>;
53
+ error?: string;
54
+ timestamp: number;
55
+ }
56
+ /**
57
+ * Interface for provider-specific health checking logic.
58
+ */
59
+ interface IProviderHealthChecker {
60
+ /**
61
+ * Performs a health check for a specific provider.
62
+ * @param config - The configuration object used to connect to the provider.
63
+ * @returns A promise that resolves to the health check result.
64
+ */
65
+ check(config: Record<string, unknown>): Promise<HealthCheckResult>;
66
+ }
67
+
68
+ /**
69
+ * VectorPlugin — main orchestrator class.
70
+ * This is the primary interface for host applications.
71
+ *
72
+ * Features:
73
+ * - Configuration resolution from host + environment
74
+ * - Configuration validation with detailed error messages
75
+ * - Provider health checks before initialization
76
+ * - Multi-provider support (Vector DBs & LLMs)
77
+ * - Per-tenant data isolation via namespacing
78
+ */
79
+ declare class VectorPlugin {
80
+ private config;
81
+ private pipeline;
82
+ private validationPromise;
83
+ constructor(hostConfig?: Partial<RagConfig>);
84
+ /**
85
+ * Get the current resolved configuration.
86
+ */
87
+ getConfig(): RagConfig;
88
+ /**
89
+ * Perform pre-flight health checks on all configured providers.
90
+ * Useful to verify connectivity before running operations.
91
+ *
92
+ * @returns Health status for vector DB, LLM, and embedding providers
93
+ */
94
+ checkHealth(): Promise<{
95
+ vectorDb: HealthCheckResult;
96
+ llm: HealthCheckResult;
97
+ embedding?: HealthCheckResult;
98
+ allHealthy: boolean;
99
+ }>;
100
+ /**
101
+ * Run a chat query.
102
+ */
103
+ chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
104
+ /**
105
+ * Run a streaming chat query.
106
+ */
107
+ chatStream(message: string, history?: ChatMessage[], namespace?: string): AsyncGenerator<string | ChatResponse, void, any>;
108
+ /**
109
+ * Ingest documents into the vector database.
110
+ */
111
+ ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
112
+ docId: string | number;
113
+ chunksIngested: number;
114
+ }>>;
115
+ }
116
+
117
+ /**
118
+ * Encode a payload as a Server-Sent Events frame.
119
+ * data: <json>\n\n
120
+ */
121
+ declare function sseFrame(payload: unknown): string;
122
+ /** Encode a plain text chunk as an SSE frame. */
123
+ declare function sseTextFrame(text: string): string;
124
+ /** Encode the retrieval metadata as an SSE frame. */
125
+ declare function sseMetaFrame(meta: unknown): string;
126
+ /** Encode a stream error as an SSE frame. */
127
+ declare function sseErrorFrame(message: string): string;
128
+ /**
129
+ * createChatHandler — factory that returns a Next.js App Router POST handler.
130
+ *
131
+ * Accepts either a full/partial `RagConfig` **or** a pre-built `VectorPlugin`
132
+ * instance (preferred for singleton/multi-tenant setups).
133
+ *
134
+ * @example
135
+ * // Option A — pass config (plugin created once at module load time)
136
+ * export const POST = createChatHandler(getRagConfig());
137
+ *
138
+ * // Option B — pass a pre-built plugin (most flexible)
139
+ * const plugin = new VectorPlugin(getRagConfig());
140
+ * export const POST = createChatHandler(plugin);
141
+ */
142
+ declare function createChatHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<NextResponse<{
143
+ error: string;
144
+ }> | NextResponse<ChatResponse>>;
145
+ /**
146
+ * createStreamHandler — factory for a streaming SSE Next.js App Router POST handler.
147
+ *
148
+ * Streams the assistant response as Server-Sent Events (SSE). Each frame is a
149
+ * JSON object with a `type` discriminant:
150
+ * - `{ type: "text", text: "..." }` — incremental text chunk
151
+ * - `{ type: "metadata", sources: [...] }` — retrieval metadata (last frame)
152
+ * - `{ type: "error", error: "..." }` — stream-level error
153
+ *
154
+ * @example
155
+ * // src/app/api/chat/route.ts
156
+ * export const POST = createStreamHandler(getRagConfig());
157
+ *
158
+ * // Client-side parsing in useRagChat.ts:
159
+ * // const lines = chunk.split('\n');
160
+ * // for (const line of lines) {
161
+ * // if (line.startsWith('data: ')) {
162
+ * // const frame = JSON.parse(line.slice(6));
163
+ * // if (frame.type === 'text') { ... }
164
+ * // }
165
+ * // }
166
+ */
167
+ declare function createStreamHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<Response>;
168
+ /**
169
+ * createIngestHandler — factory for the document ingestion endpoint.
170
+ */
171
+ declare function createIngestHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<NextResponse<{
172
+ error: string;
173
+ }> | NextResponse<{
174
+ results: {
175
+ docId: string | number;
176
+ chunksIngested: number;
177
+ }[];
178
+ }>>;
179
+ /**
180
+ * createHealthHandler — factory for the health-check endpoint.
181
+ */
182
+ declare function createHealthHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): () => Promise<NextResponse<{
183
+ timestamp: string;
184
+ vectorDb: HealthCheckResult;
185
+ llm: HealthCheckResult;
186
+ embedding?: HealthCheckResult;
187
+ allHealthy: boolean;
188
+ status: string;
189
+ }> | NextResponse<{
190
+ status: string;
191
+ error: string;
192
+ }>>;
193
+ /**
194
+ * createUploadHandler — factory for the file upload ingestion endpoint.
195
+ */
196
+ declare function createUploadHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin): (req: NextRequest) => Promise<NextResponse<{
197
+ error: string;
198
+ }> | NextResponse<{
199
+ message: string;
200
+ results: {
201
+ docId: string | number;
202
+ chunksIngested: number;
203
+ }[];
204
+ }>>;
205
+
206
+ export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, VectorPlugin as b, createChatHandler as c, createHealthHandler as d, createIngestHandler as e, createStreamHandler as f, createUploadHandler as g, sseFrame as h, sseMetaFrame as i, sseTextFrame as j, sseErrorFrame as s };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import React$1, { ReactNode } from 'react';
2
- import { C as ChatMessage } from './DocumentChunker-C-sCZPhi.mjs';
3
- export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-C-sCZPhi.mjs';
4
- import { V as VectorMatch, U as UIConfig } from './RagConfig-DRJO4hGU.mjs';
5
- export { C as ChatResponse, E as EmbeddingConfig, a as EmbeddingProvider, I as IngestDocument, L as LLMConfig, b as LLMProvider, R as RAGConfig, c as RagConfig, d as UpsertDocument, e as VectorDBConfig, f as VectorDBProvider } from './RagConfig-DRJO4hGU.mjs';
2
+ import { C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-BEmz4hVP.mjs';
3
+ export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-BEmz4hVP.mjs';
4
+ export { C as Chunk, a as ChunkOptions } from './DocumentChunker-Dh9TvmGG.mjs';
6
5
 
7
6
  interface ChatWidgetProps {
8
7
  /** Position of the floating button. Defaults to bottom-right. */
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import React$1, { ReactNode } from 'react';
2
- import { C as ChatMessage } from './DocumentChunker-C-sCZPhi.js';
3
- export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-C-sCZPhi.js';
4
- import { V as VectorMatch, U as UIConfig } from './RagConfig-DRJO4hGU.js';
5
- export { C as ChatResponse, E as EmbeddingConfig, a as EmbeddingProvider, I as IngestDocument, L as LLMConfig, b as LLMProvider, R as RAGConfig, c as RagConfig, d as UpsertDocument, e as VectorDBConfig, f as VectorDBProvider } from './RagConfig-DRJO4hGU.js';
2
+ import { C as ChatMessage, V as VectorMatch, U as UIConfig } from './RagConfig-BEmz4hVP.js';
3
+ export { a as ChatOptions, b as ChatResponse, E as EmbedOptions, c as EmbeddingConfig, d as EmbeddingProvider, I as ILLMProvider, e as IngestDocument, L as LLMConfig, f as LLMProvider, R as RAGConfig, g as RagConfig, h as UpsertDocument, i as VectorDBConfig, j as VectorDBProvider } from './RagConfig-BEmz4hVP.js';
4
+ export { C as Chunk, a as ChunkOptions } from './DocumentChunker-Dh9TvmGG.js';
6
5
 
7
6
  interface ChatWidgetProps {
8
7
  /** Position of the floating button. Defaults to bottom-right. */