@retrivora-ai/rag-engine 2.3.0 → 2.3.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.
- package/dist/{LicenseValidator-CENvo9o2.d.mts → BatchProcessor-7yV-UCHW.d.mts} +142 -3
- package/dist/{LicenseValidator-CsjJp2PP.d.ts → BatchProcessor-BfzuU4cK.d.ts} +142 -3
- package/dist/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +880 -327
- package/dist/handlers/index.mjs +880 -327
- package/dist/index-DR_O_B-W.d.ts +394 -0
- package/dist/index-fnpaCuma.d.mts +394 -0
- package/dist/index.css +58 -0
- package/dist/index.d.mts +63 -3
- package/dist/index.d.ts +63 -3
- package/dist/index.js +452 -35
- package/dist/index.mjs +451 -37
- package/dist/server.d.mts +35 -73
- package/dist/server.d.ts +35 -73
- package/dist/server.js +910 -341
- package/dist/server.mjs +910 -341
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +147 -46
- package/src/components/ChatWindow.tsx +52 -8
- package/src/core/BatchProcessor.ts +42 -4
- package/src/core/CircuitBreaker.ts +118 -0
- package/src/core/DatabaseStorage.ts +55 -24
- package/src/core/FreeTierLimitsGuard.ts +281 -0
- package/src/core/LicenseValidator.ts +66 -2
- package/src/core/LicenseVerifier.ts +31 -3
- package/src/core/VectorPlugin.ts +30 -0
- package/src/handlers/index.ts +491 -36
- package/src/index.css +58 -0
- package/src/index.ts +4 -0
- package/src/server.ts +1 -0
- package/dist/index-BPJ3KDYI.d.ts +0 -195
- package/dist/index-Dmq5lH0j.d.mts +0 -195
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { i as RagConfig, I as ILLMProvider, C as ChatMessage, c as ChatResponse, f as IngestDocument } from './ILLMProvider-teTNQ1lh.js';
|
|
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
|
+
* Get the initialized LLM provider (available after the first request).
|
|
90
|
+
* Used by handlers to pass to UITransformer.analyzeAndDecide() for
|
|
91
|
+
* LLM-driven visualization decisions.
|
|
92
|
+
*/
|
|
93
|
+
getLLMProvider(): ILLMProvider | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Perform pre-flight health checks on all configured providers.
|
|
96
|
+
* Useful to verify connectivity before running operations.
|
|
97
|
+
*
|
|
98
|
+
* @returns Health status for vector DB, LLM, and embedding providers
|
|
99
|
+
*/
|
|
100
|
+
checkHealth(): Promise<{
|
|
101
|
+
vectorDb: HealthCheckResult;
|
|
102
|
+
llm: HealthCheckResult;
|
|
103
|
+
embedding?: HealthCheckResult;
|
|
104
|
+
allHealthy: boolean;
|
|
105
|
+
}>;
|
|
106
|
+
private estimateInputTokens;
|
|
107
|
+
/**
|
|
108
|
+
* Run a chat query.
|
|
109
|
+
*/
|
|
110
|
+
chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
111
|
+
/**
|
|
112
|
+
* Run a streaming chat query.
|
|
113
|
+
*/
|
|
114
|
+
chatStream(message: string, history?: ChatMessage[], namespace?: string): AsyncGenerator<string | ChatResponse, void, unknown>;
|
|
115
|
+
/**
|
|
116
|
+
* Ingest documents into the vector database.
|
|
117
|
+
*/
|
|
118
|
+
ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
|
|
119
|
+
docId: string | number;
|
|
120
|
+
chunksIngested: number;
|
|
121
|
+
}>>;
|
|
122
|
+
/**
|
|
123
|
+
* Get auto-suggestions based on a query prefix.
|
|
124
|
+
*/
|
|
125
|
+
getSuggestions(query: string, namespace?: string): Promise<string[]>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Shared options accepted by every handler factory.
|
|
130
|
+
*
|
|
131
|
+
* Pass `onAuthorize` to plug in per-request auth rules; the callback is
|
|
132
|
+
* called before rate-limiting, license enforcement, or any business logic
|
|
133
|
+
* runs. Return `true` or the resolved promise `true` to allow, `false`
|
|
134
|
+
* to get a 401, or return a `Response` to fully control the denial (for
|
|
135
|
+
* example redirecting an OAuth-style flow to a login page).
|
|
136
|
+
*/
|
|
137
|
+
interface HandlerOptions {
|
|
138
|
+
/** Optional synchronous or asynchronous authorization gate. */
|
|
139
|
+
onAuthorize?: (req: NextRequest) => boolean | Response | Promise<boolean | Response>;
|
|
140
|
+
/**
|
|
141
|
+
* Optional scope resolver for multi-tenant deployments.
|
|
142
|
+
*
|
|
143
|
+
* Returns an allow-list of project ids that the caller is authorized to
|
|
144
|
+
* access on the `sessions`, `history`, and `feedback` endpoints. When
|
|
145
|
+
* the callback returns a non-empty array, server-side filtering is
|
|
146
|
+
* applied to every `listSessions`, `getHistory`, `clearHistory`,
|
|
147
|
+
* `listFeedback`, and `getFeedback` call so the caller can never leak
|
|
148
|
+
* another tenant's data even when client-side filters are tampered with.
|
|
149
|
+
*/
|
|
150
|
+
onResolveScope?: (req: NextRequest) => string[] | undefined | Promise<string[] | undefined>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Encode a payload as a Server-Sent Events frame.
|
|
154
|
+
* data: <json>\n\n
|
|
155
|
+
*/
|
|
156
|
+
declare function sseFrame(payload: unknown): string;
|
|
157
|
+
/** Encode a plain text chunk as an SSE frame. */
|
|
158
|
+
declare function sseTextFrame(text: string): string;
|
|
159
|
+
/** Encode the retrieval metadata with UI transformation as an SSE frame. */
|
|
160
|
+
declare function sseMetaFrame(meta: unknown): string;
|
|
161
|
+
/** Encode the UI transformation result as an SSE frame. */
|
|
162
|
+
declare function sseUIFrame(uiTransformation: unknown): string;
|
|
163
|
+
/** Encode the observability trace as an SSE frame. */
|
|
164
|
+
declare function sseObservabilityFrame(trace: unknown): string;
|
|
165
|
+
/** Encode a stream error as an SSE frame. */
|
|
166
|
+
declare function sseErrorFrame(message: string): string;
|
|
167
|
+
/**
|
|
168
|
+
* Build a Next.js App Router POST handler for **synchronous** RAG chat.
|
|
169
|
+
*
|
|
170
|
+
* Pipeline (in execution order):
|
|
171
|
+
* 1. `options.onAuthorize` — custom authorization gate (optional)
|
|
172
|
+
* 2. In-memory IP rate limiter (30 req / 60 s sliding window)
|
|
173
|
+
* 3. JSON body parse → `enforceLicense()` RSA signature validation
|
|
174
|
+
* 4. Input sanitization + length / toxicity / PII / prompt-injection heuristics
|
|
175
|
+
* 5. User-message persistence via `DatabaseStorage`
|
|
176
|
+
* 6. LLM-driven RAG retrieval via `plugin.chat()`
|
|
177
|
+
* 7. Observability UI transformation + response persistence
|
|
178
|
+
* 8. JSON response (`ChatResponse` shape)
|
|
179
|
+
*
|
|
180
|
+
* Use this handler when you don't need streaming (e.g. server-side SDKs).
|
|
181
|
+
* For streaming use `createStreamHandler` — the same pipeline but with
|
|
182
|
+
* Server-Sent Events for incremental tokens.
|
|
183
|
+
*
|
|
184
|
+
* @param configOrPlugin - Either a partial `RagConfig` (a plugin will be
|
|
185
|
+
* created or reused for you) or an already-constructed
|
|
186
|
+
* `VectorPlugin` instance.
|
|
187
|
+
* @param options - See `HandlerOptions`. `onAuthorize` is recommended
|
|
188
|
+
* for multi-tenant deployments to gate access.
|
|
189
|
+
* @returns An async `POST(req, ctx)` function suitable for being the default
|
|
190
|
+
* export of a Next.js route file.
|
|
191
|
+
*/
|
|
192
|
+
declare function createChatHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: any, context?: any) => Promise<any>;
|
|
193
|
+
/**
|
|
194
|
+
* Build a Next.js App Router POST handler for **streaming** RAG chat via SSE.
|
|
195
|
+
*
|
|
196
|
+
* Same pipeline as `createChatHandler`, but the `plugin.chat()` call is run
|
|
197
|
+
* in streaming mode and every token is immediately emitted as a Server-Sent
|
|
198
|
+
* Event frame. The stream contains frames for `text`, `thinking`,
|
|
199
|
+
* `metadata`, `ui_transformation`, `observability`, and a terminal `done`.
|
|
200
|
+
*
|
|
201
|
+
* Multipart upload short-circuit: When the request `Content-Type` is
|
|
202
|
+
* `multipart/form-data` the request is transparently delegated to
|
|
203
|
+
* `createUploadHandler` (which also runs its own `enforceLicense()` gate).
|
|
204
|
+
*
|
|
205
|
+
* Pipeline (in execution order):
|
|
206
|
+
* 1. `options.onAuthorize` — custom authorization gate (optional)
|
|
207
|
+
* 2. In-memory IP rate limiter (30 req / 60 s sliding window)
|
|
208
|
+
* 3. JSON body parse (or form-data upload delegation)
|
|
209
|
+
* 4. `enforceLicense()` RSA signature validation — 403 if missing / terminated
|
|
210
|
+
* 5. Input sanitization + length / toxicity / PII / prompt-injection heuristics
|
|
211
|
+
* 6. User-message persistence via `DatabaseStorage`
|
|
212
|
+
* 7. Streaming RAG retrieval via `plugin.chat({ stream: true })`
|
|
213
|
+
* 8. Persist assistant message + emit SSE frames
|
|
214
|
+
*
|
|
215
|
+
* @param configOrPlugin - Partial `RagConfig` or an existing `VectorPlugin`.
|
|
216
|
+
* @param options - See `HandlerOptions`.
|
|
217
|
+
* @returns Async `POST(req, ctx)` function for `app/.../route.ts`.
|
|
218
|
+
*/
|
|
219
|
+
declare function createStreamHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: any, context?: any) => Promise<any>;
|
|
220
|
+
/**
|
|
221
|
+
* Build a POST handler that ingests raw pre-parsed documents into the vector DB.
|
|
222
|
+
*
|
|
223
|
+
* Unlike `createUploadHandler` (which takes files and does parsing/splitting),
|
|
224
|
+
* this endpoint expects the caller to supply `documents[]` already split and
|
|
225
|
+
* prepared. This is useful for bulk backfill jobs, migrations, or programmatic
|
|
226
|
+
* sync pipelines.
|
|
227
|
+
*
|
|
228
|
+
* Security: Requires a valid license (RSA signature check via `enforceLicense`)
|
|
229
|
+
* AFTER JSON body parse so the optional `body.licenseKey` override is read.
|
|
230
|
+
*
|
|
231
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
232
|
+
* @param options - Optional `onAuthorize` gate.
|
|
233
|
+
* @returns Async POST handler.
|
|
234
|
+
*/
|
|
235
|
+
declare function createIngestHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: any, context?: any) => Promise<any>;
|
|
236
|
+
/**
|
|
237
|
+
* Build a GET handler that returns health / readiness status.
|
|
238
|
+
*
|
|
239
|
+
* Response shape (200 OK):
|
|
240
|
+
* ```json
|
|
241
|
+
* {
|
|
242
|
+
* "ok": true,
|
|
243
|
+
* "status": "healthy",
|
|
244
|
+
* "sdkVersion": "x.y.z",
|
|
245
|
+
* "timestamp": "ISO string",
|
|
246
|
+
* "embedding": { "provider": "...", "ok": true },
|
|
247
|
+
* "vectorStore": { "provider": "...", "ok": true }
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* License check: This endpoint is intentionally **NOT** license-gated so
|
|
252
|
+
* orchestrators (Kubernetes, uptime probes, Vercel cron pings) can use it
|
|
253
|
+
* to assert the process is alive even when no license has been configured
|
|
254
|
+
* yet during deploy.
|
|
255
|
+
*
|
|
256
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
257
|
+
* @param options - Optional `onAuthorize` gate (rarely used here).
|
|
258
|
+
* @returns Async GET handler.
|
|
259
|
+
*/
|
|
260
|
+
declare function createHealthHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req?: NextRequest) => Promise<any>;
|
|
261
|
+
/**
|
|
262
|
+
* Build a POST handler for the SDK-facing `/v1/license/validate` endpoint.
|
|
263
|
+
*
|
|
264
|
+
* Client flow: `LicenseValidator.validate()` calls this URL, receives
|
|
265
|
+
* authoritative DB-backed status (ACTIVE / TERMINATED / SUSPENDED / EXPIRED /
|
|
266
|
+
* REVOKED), and falls back to pure-local `LicenseVerifier.verify()` if the
|
|
267
|
+
* server is unreachable or returns an error.
|
|
268
|
+
*
|
|
269
|
+
* This handler does NOT enforce license — it is the verifier itself. It does,
|
|
270
|
+
* however, still apply rate limiting to mitigate abuse.
|
|
271
|
+
*
|
|
272
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
273
|
+
* @param options - Optional `onAuthorize` gate.
|
|
274
|
+
* @returns Async POST handler returning `LicenseValidationResponse` JSON.
|
|
275
|
+
*/
|
|
276
|
+
declare function createLicenseHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: NextRequest) => Promise<any>;
|
|
277
|
+
/**
|
|
278
|
+
* Build a POST handler that accepts `multipart/form-data` file uploads.
|
|
279
|
+
*
|
|
280
|
+
* Workflow:
|
|
281
|
+
* 1. `onAuthorize` → license enforcement via `enforceLicense` (no JSON body,
|
|
282
|
+
* so the key must come from headers or the environment).
|
|
283
|
+
* 2. Read FormData files[] list → max 25 files per request, 100 MB each.
|
|
284
|
+
* 3. Per-file: use `DocumentParser` to extract raw text by MIME type (PDF,
|
|
285
|
+
* DOCX, TXT, MD, HTML, JSON, CSV, images via OCR fallback, etc.).
|
|
286
|
+
* 4. Chunk by the configured chunker (RecursiveCharacter, semantic, etc.).
|
|
287
|
+
* 5. Call `plugin.ingest()` to embed and insert into the vector store.
|
|
288
|
+
* 6. Return JSON summary per file (status, chunks ingested, docId).
|
|
289
|
+
*
|
|
290
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
291
|
+
* @param options - Optional `onAuthorize` gate.
|
|
292
|
+
* @returns Async POST handler.
|
|
293
|
+
*/
|
|
294
|
+
declare function createUploadHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: any, context?: any) => Promise<any>;
|
|
295
|
+
/**
|
|
296
|
+
* Build a GET/POST handler for auto-suggestions (used by ChatWidget prompt chips).
|
|
297
|
+
*
|
|
298
|
+
* Requests:
|
|
299
|
+
* - GET `?query=...&namespace=...`
|
|
300
|
+
* - POST `{ query: string, namespace?: string, licenseKey?: string }`
|
|
301
|
+
*
|
|
302
|
+
* Response (200 OK): `{ suggestions: string[] }`
|
|
303
|
+
*
|
|
304
|
+
* License enforcement: Runs BEFORE body parse on headers/env, and if the POST
|
|
305
|
+
* body contains a `licenseKey` override the check is repeated with the body
|
|
306
|
+
* key included so the per-request override is honored.
|
|
307
|
+
*
|
|
308
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
309
|
+
* @param options - Optional `onAuthorize` gate.
|
|
310
|
+
* @returns Async handler accepting both GET and POST methods.
|
|
311
|
+
*/
|
|
312
|
+
declare function createSuggestionsHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: NextRequest) => Promise<any>;
|
|
313
|
+
/**
|
|
314
|
+
* Build a handler for chat-history listing and clearing.
|
|
315
|
+
*
|
|
316
|
+
* Routes dispatched by `createRagHandler`:
|
|
317
|
+
* - GET `/history?sessionId=...&limit=...` → returns `{ messages: HistoryMessage[] }`
|
|
318
|
+
* - POST `/history/clear` with `{ sessionId? }` JSON body → returns `{ ok: true }`
|
|
319
|
+
*
|
|
320
|
+
* Storage: Uses `DatabaseStorage` (default SQLite or custom configured driver).
|
|
321
|
+
* License enforcement is handled by the upstream `createRagHandler` router when
|
|
322
|
+
* this handler is composed through it; standalone usage is rare.
|
|
323
|
+
*
|
|
324
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
325
|
+
* @param options - Optional `onAuthorize` gate.
|
|
326
|
+
* @returns Async handler accepting GET (list) or POST (clear) methods.
|
|
327
|
+
*/
|
|
328
|
+
declare function createHistoryHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: NextRequest) => Promise<any>;
|
|
329
|
+
/**
|
|
330
|
+
* Build a POST handler for collecting thumbs-up / thumbs-down user feedback.
|
|
331
|
+
*
|
|
332
|
+
* Request: `{ messageId, sessionId?, rating: 1 | -1, comment?, reason? }`
|
|
333
|
+
* Response: `{ ok: true, id: string }` (201 Created)
|
|
334
|
+
*
|
|
335
|
+
* Feedback is written to `DatabaseStorage.feedback` for RAG pipeline
|
|
336
|
+
* evaluation, offline fine-tuning dataset curation, and support triage.
|
|
337
|
+
*
|
|
338
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
339
|
+
* @param options - Optional `onAuthorize` gate.
|
|
340
|
+
* @returns Async POST handler.
|
|
341
|
+
*/
|
|
342
|
+
declare function createFeedbackHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req: NextRequest) => Promise<any>;
|
|
343
|
+
/**
|
|
344
|
+
* Build a GET handler that lists the set of chat sessions.
|
|
345
|
+
*
|
|
346
|
+
* Response: `{ sessions: { id, title, lastMessageAt, preview }[] }`
|
|
347
|
+
*
|
|
348
|
+
* Sessions are read from `DatabaseStorage`. Combined with `createHistoryHandler`
|
|
349
|
+
* this enables a sidebar of prior conversations for custom UIs built on top of
|
|
350
|
+
* the `useRagChat` headless hook.
|
|
351
|
+
*
|
|
352
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
353
|
+
* @param options - Optional `onAuthorize` gate.
|
|
354
|
+
* @returns Async GET handler returning a session listing.
|
|
355
|
+
*/
|
|
356
|
+
declare function createSessionsHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): (req?: NextRequest) => Promise<any>;
|
|
357
|
+
/**
|
|
358
|
+
* Build a Next.js catch-all route that dispatches to every sub-handler by path.
|
|
359
|
+
*
|
|
360
|
+
* Intended drop-in export:
|
|
361
|
+
* ```ts
|
|
362
|
+
* // app/api/retrivora/[[...retrivora]]/route.ts
|
|
363
|
+
* import { createRagHandler } from '@retrivora-ai/rag-engine';
|
|
364
|
+
* const { GET, POST } = createRagHandler({ /* RagConfig *\/ });
|
|
365
|
+
* export { GET, POST };
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* Segments dispatched (POST unless marked GET):
|
|
369
|
+
* - `chat` → createStreamHandler (SSE streaming chat)
|
|
370
|
+
* - `upload` → createUploadHandler (file ingestion)
|
|
371
|
+
* - `suggestions` → createSuggestionsHandler (GET/POST)
|
|
372
|
+
* - `v1/license/validate` → createLicenseHandler
|
|
373
|
+
* - `health` → createHealthHandler (GET)
|
|
374
|
+
* - `feedback` → createFeedbackHandler
|
|
375
|
+
* - `history` → createHistoryHandler (GET/POST)
|
|
376
|
+
* - `sessions` → createSessionsHandler (GET)
|
|
377
|
+
* - Any other segment → 404 with a JSON error body
|
|
378
|
+
*
|
|
379
|
+
* This is the **recommended** way to mount the SDK in a Next.js app. Using
|
|
380
|
+
* any single handler individually without its license enforcement gate is a
|
|
381
|
+
* security anti-pattern — prefer `createRagHandler` unless you have a very
|
|
382
|
+
* specific reason to split routes up.
|
|
383
|
+
*
|
|
384
|
+
* @param configOrPlugin - Partial `RagConfig` or existing `VectorPlugin`.
|
|
385
|
+
* @param options - Optional `onAuthorize` gate (propagated to every
|
|
386
|
+
* sub-handler so auth rules apply uniformly).
|
|
387
|
+
* @returns An object `{ GET, POST }` to re-export as your route file defaults.
|
|
388
|
+
*/
|
|
389
|
+
declare function createRagHandler(configOrPlugin?: Partial<RagConfig> | VectorPlugin, options?: HandlerOptions): {
|
|
390
|
+
GET: (req: any, context?: any) => Promise<any>;
|
|
391
|
+
POST: (req: any, context?: any) => Promise<any>;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
export { ConfigValidator as C, type HealthCheckResult as H, type IProviderValidator as I, type ValidationError as V, type IProviderHealthChecker as a, type HandlerOptions as b, VectorPlugin as c, createChatHandler as d, createFeedbackHandler as e, createHealthHandler as f, createHistoryHandler as g, createIngestHandler as h, createRagHandler as i, createSessionsHandler as j, createStreamHandler as k, createUploadHandler as l, sseFrame as m, sseMetaFrame as n, sseTextFrame as o, createLicenseHandler as p, createSuggestionsHandler as q, sseObservabilityFrame as r, sseErrorFrame as s, sseUIFrame as t };
|