@retrivora-ai/rag-engine 1.9.8 → 1.9.9
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/README.md +36 -28
- package/dist/{ILLMProvider-B8ROITYK.d.mts → ILLMProvider-DMxLyTdq.d.mts} +2 -2
- package/dist/{ILLMProvider-B8ROITYK.d.ts → ILLMProvider-DMxLyTdq.d.ts} +2 -2
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +140 -28
- package/dist/handlers/index.mjs +146 -28
- package/dist/{index-DNvoi-sV.d.ts → index-CfkqZd2Y.d.ts} +1 -1
- package/dist/{index-CrxCy36A.d.mts → index-DXd29KMq.d.mts} +1 -1
- package/dist/{index-BCPKUAVL.d.ts → index-D_bOdJML.d.ts} +1 -1
- package/dist/{index-B8PbEFSY.d.mts → index-xygonxpW.d.mts} +1 -1
- package/dist/index.css +485 -557
- package/dist/index.d.mts +16 -10
- package/dist/index.d.ts +16 -10
- package/dist/index.js +24 -765
- package/dist/index.mjs +20 -779
- package/dist/server.d.mts +8 -5
- package/dist/server.d.ts +8 -5
- package/dist/server.js +141 -28
- package/dist/server.mjs +147 -28
- package/package.json +3 -2
- package/src/app/page.tsx +2 -0
- package/src/components/constants.tsx +224 -0
- package/src/config/RagConfig.ts +2 -2
- package/src/core/ConfigResolver.ts +32 -6
- package/src/core/LicenseVerifier.ts +106 -0
- package/src/core/Pipeline.ts +8 -6
- package/src/core/Retrivora.ts +1 -0
- package/src/index.ts +3 -5
- package/src/components/AmbientBackground.tsx +0 -29
- package/src/components/ArchitectureCard.tsx +0 -53
- package/src/components/ArchitectureCardsSection.tsx +0 -48
- package/src/components/DocViewer.tsx +0 -97
- package/src/components/Documentation.tsx +0 -141
- package/src/components/Hero.tsx +0 -142
- package/src/components/Lifecycle.tsx +0 -77
- package/src/components/Navbar.tsx +0 -55
package/README.md
CHANGED
|
@@ -18,34 +18,42 @@ The SDK is a unified suite designed to abstract the complexity of building produ
|
|
|
18
18
|
|
|
19
19
|
The SDK is built with modularity, performance, and security at its core:
|
|
20
20
|
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
21
|
+
```mermaid
|
|
22
|
+
sequenceDiagram
|
|
23
|
+
autonumber
|
|
24
|
+
actor Client as Host Client (Next.js/React)
|
|
25
|
+
participant Facade as Retrivora Facade
|
|
26
|
+
participant Lic as LicenseVerifier
|
|
27
|
+
participant Pipe as Pipeline Engine
|
|
28
|
+
participant DB as Vector Database
|
|
29
|
+
participant LLM as LLM Provider
|
|
30
|
+
|
|
31
|
+
Client->>Facade: initialize(config)
|
|
32
|
+
activate Facade
|
|
33
|
+
Facade->>Lic: verify(licenseKey, projectId)
|
|
34
|
+
activate Lic
|
|
35
|
+
Note over Lic: Offline RS256 JWT Decryption
|
|
36
|
+
Lic-->>Facade: Valid Signature (Green)
|
|
37
|
+
deactivate Lic
|
|
38
|
+
Facade-->>Client: Ready
|
|
39
|
+
deactivate Facade
|
|
40
|
+
|
|
41
|
+
Client->>Facade: ask(question, history)
|
|
42
|
+
activate Facade
|
|
43
|
+
Facade->>Pipe: ask(question, history)
|
|
44
|
+
activate Pipe
|
|
45
|
+
Pipe->>DB: search(queryVector)
|
|
46
|
+
activate DB
|
|
47
|
+
DB-->>Pipe: relevant chunks & meta
|
|
48
|
+
deactivate DB
|
|
49
|
+
Pipe->>LLM: chatCompletion(context, prompt)
|
|
50
|
+
activate LLM
|
|
51
|
+
LLM-->>Pipe: generated response
|
|
52
|
+
deactivate LLM
|
|
53
|
+
Pipe-->>Facade: ChatResponse (reply + sources)
|
|
54
|
+
deactivate Pipe
|
|
55
|
+
Facade-->>Client: SSE Streaming Chunk / JSON
|
|
56
|
+
deactivate Facade
|
|
49
57
|
```
|
|
50
58
|
|
|
51
59
|
### Key Components:
|
|
@@ -227,7 +227,7 @@ interface RAGConfig {
|
|
|
227
227
|
/** Characters used to split text, in order of priority */
|
|
228
228
|
separators?: string[];
|
|
229
229
|
/** Overall RAG architecture pattern */
|
|
230
|
-
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic';
|
|
230
|
+
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic' | 'naive' | 'retrieve-and-rerank' | 'multimodal' | 'agentic-router' | 'multi-agent';
|
|
231
231
|
/** Chunking strategy to use during ingestion */
|
|
232
232
|
chunkingStrategy?: 'recursive' | 'markdown' | 'semantic' | 'llamaindex';
|
|
233
233
|
/** Whether to use query transformation (e.g. HyDE) */
|
|
@@ -282,7 +282,7 @@ interface RetrievalConfig {
|
|
|
282
282
|
}
|
|
283
283
|
interface WorkflowConfig {
|
|
284
284
|
/** High-level workflow selector from the SDK prompt. */
|
|
285
|
-
type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic';
|
|
285
|
+
type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic' | 'naive-rag' | 'retrieve-and-rerank' | 'multimodal-rag' | 'agentic-router' | 'multi-agent-rag' | 'multi-agent';
|
|
286
286
|
/** Future workflow/provider-specific options. */
|
|
287
287
|
options?: Record<string, unknown>;
|
|
288
288
|
}
|
|
@@ -227,7 +227,7 @@ interface RAGConfig {
|
|
|
227
227
|
/** Characters used to split text, in order of priority */
|
|
228
228
|
separators?: string[];
|
|
229
229
|
/** Overall RAG architecture pattern */
|
|
230
|
-
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic';
|
|
230
|
+
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic' | 'naive' | 'retrieve-and-rerank' | 'multimodal' | 'agentic-router' | 'multi-agent';
|
|
231
231
|
/** Chunking strategy to use during ingestion */
|
|
232
232
|
chunkingStrategy?: 'recursive' | 'markdown' | 'semantic' | 'llamaindex';
|
|
233
233
|
/** Whether to use query transformation (e.g. HyDE) */
|
|
@@ -282,7 +282,7 @@ interface RetrievalConfig {
|
|
|
282
282
|
}
|
|
283
283
|
interface WorkflowConfig {
|
|
284
284
|
/** High-level workflow selector from the SDK prompt. */
|
|
285
|
-
type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic';
|
|
285
|
+
type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic' | 'naive-rag' | 'retrieve-and-rerank' | 'multimodal-rag' | 'agentic-router' | 'multi-agent-rag' | 'multi-agent';
|
|
286
286
|
/** Future workflow/provider-specific options. */
|
|
287
287
|
options?: Record<string, unknown>;
|
|
288
288
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'next/server';
|
|
2
|
-
export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-
|
|
3
|
-
import '../ILLMProvider-
|
|
2
|
+
export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-DXd29KMq.mjs';
|
|
3
|
+
import '../ILLMProvider-DMxLyTdq.mjs';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'next/server';
|
|
2
|
-
export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-
|
|
3
|
-
import '../ILLMProvider-
|
|
2
|
+
export { o as HandlerOptions, c as createChatHandler, d as createFeedbackHandler, e as createHealthHandler, f as createHistoryHandler, g as createIngestHandler, h as createRagHandler, i as createSessionsHandler, j as createStreamHandler, p as createSuggestionsHandler, k as createUploadHandler, s as sseErrorFrame, l as sseFrame, m as sseMetaFrame, q as sseObservabilityFrame, n as sseTextFrame, r as sseUIFrame } from '../index-D_bOdJML.js';
|
|
3
|
+
import '../ILLMProvider-DMxLyTdq.js';
|
package/dist/handlers/index.js
CHANGED
|
@@ -2385,7 +2385,7 @@ var ConfigResolver = class {
|
|
|
2385
2385
|
}
|
|
2386
2386
|
}
|
|
2387
2387
|
static mergeRetrievalWorkflow(rag, retrieval, workflow) {
|
|
2388
|
-
var _a2, _b, _c, _d, _e;
|
|
2388
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2389
2389
|
if (!rag && !retrieval && !workflow) return void 0;
|
|
2390
2390
|
const normalized = __spreadValues({}, rag != null ? rag : {});
|
|
2391
2391
|
if (retrieval) {
|
|
@@ -2393,20 +2393,44 @@ var ConfigResolver = class {
|
|
|
2393
2393
|
normalized.scoreThreshold = (_b = retrieval.scoreThreshold) != null ? _b : normalized.scoreThreshold;
|
|
2394
2394
|
normalized.useReranking = (_c = retrieval.useReranking) != null ? _c : normalized.useReranking;
|
|
2395
2395
|
if (retrieval.strategy === "hybrid") normalized.architecture = (_d = normalized.architecture) != null ? _d : "hybrid";
|
|
2396
|
-
if (retrieval.strategy === "agentic") normalized.architecture = "
|
|
2397
|
-
if (retrieval.strategy === "contextual-compression")
|
|
2396
|
+
if (retrieval.strategy === "agentic") normalized.architecture = "multi-agent";
|
|
2397
|
+
if (retrieval.strategy === "contextual-compression") {
|
|
2398
|
+
normalized.useReranking = true;
|
|
2399
|
+
normalized.architecture = (_e = normalized.architecture) != null ? _e : "retrieve-and-rerank";
|
|
2400
|
+
}
|
|
2398
2401
|
}
|
|
2399
2402
|
if (workflow == null ? void 0 : workflow.type) {
|
|
2400
2403
|
const type = workflow.type;
|
|
2401
|
-
if (type === "
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
+
if (type === "naive-rag") {
|
|
2405
|
+
normalized.architecture = "naive";
|
|
2406
|
+
normalized.useReranking = false;
|
|
2407
|
+
normalized.useGraphRetrieval = false;
|
|
2408
|
+
} else if (type === "retrieve-and-rerank") {
|
|
2409
|
+
normalized.architecture = "retrieve-and-rerank";
|
|
2410
|
+
normalized.useReranking = true;
|
|
2411
|
+
} else if (type === "multimodal-rag") {
|
|
2412
|
+
normalized.architecture = "multimodal";
|
|
2413
|
+
} else if (type === "graph-rag") {
|
|
2404
2414
|
normalized.architecture = "graph";
|
|
2405
2415
|
normalized.useGraphRetrieval = true;
|
|
2416
|
+
} else if (type === "hybrid-rag") {
|
|
2417
|
+
normalized.architecture = "hybrid";
|
|
2418
|
+
} else if (type === "agentic-router") {
|
|
2419
|
+
normalized.architecture = "agentic-router";
|
|
2420
|
+
} else if (type === "multi-agent-rag" || type === "multi-agent" || type === "agentic" || type === "agentic-rag") {
|
|
2421
|
+
normalized.architecture = "multi-agent";
|
|
2406
2422
|
} else if (type === "simple-rag" || type === "rag") {
|
|
2407
|
-
normalized.architecture = (
|
|
2423
|
+
normalized.architecture = (_f = normalized.architecture) != null ? _f : "naive";
|
|
2408
2424
|
}
|
|
2409
2425
|
}
|
|
2426
|
+
if (normalized.architecture === "retrieve-and-rerank") {
|
|
2427
|
+
normalized.useReranking = true;
|
|
2428
|
+
} else if (normalized.architecture === "graph") {
|
|
2429
|
+
normalized.useGraphRetrieval = true;
|
|
2430
|
+
} else if (normalized.architecture === "naive") {
|
|
2431
|
+
normalized.useReranking = false;
|
|
2432
|
+
normalized.useGraphRetrieval = false;
|
|
2433
|
+
}
|
|
2410
2434
|
return normalized;
|
|
2411
2435
|
}
|
|
2412
2436
|
};
|
|
@@ -7152,7 +7176,7 @@ var Pipeline = class {
|
|
|
7152
7176
|
return this.initialised ? this.llmProvider : void 0;
|
|
7153
7177
|
}
|
|
7154
7178
|
async initialize() {
|
|
7155
|
-
var _a2, _b, _c;
|
|
7179
|
+
var _a2, _b, _c, _d;
|
|
7156
7180
|
if (this.initialised) return;
|
|
7157
7181
|
const chartInstruction = `You are a helpful assistant. Use the provided context to answer questions accurately.
|
|
7158
7182
|
|
|
@@ -7195,7 +7219,7 @@ var Pipeline = class {
|
|
|
7195
7219
|
this.entityExtractor = new EntityExtractor(this.llmProvider);
|
|
7196
7220
|
}
|
|
7197
7221
|
await this.vectorDB.initialize();
|
|
7198
|
-
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7222
|
+
if (((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) {
|
|
7199
7223
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
7200
7224
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
7201
7225
|
llmProvider: this.llmProvider,
|
|
@@ -7207,7 +7231,7 @@ var Pipeline = class {
|
|
|
7207
7231
|
this.agent = new LangChainAgent(this, this.config);
|
|
7208
7232
|
await this.agent.initialize(this.llmProvider);
|
|
7209
7233
|
}
|
|
7210
|
-
if ((
|
|
7234
|
+
if ((_d = (_c = this.config.rag) == null ? void 0 : _c.cag) == null ? void 0 : _d.enabled) {
|
|
7211
7235
|
await this.loadColdContext(this.config.projectId);
|
|
7212
7236
|
}
|
|
7213
7237
|
this.initialised = true;
|
|
@@ -7370,9 +7394,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7370
7394
|
return { reply, sources };
|
|
7371
7395
|
}
|
|
7372
7396
|
async ask(question, history = [], namespace) {
|
|
7373
|
-
var _a2;
|
|
7397
|
+
var _a2, _b;
|
|
7374
7398
|
await this.initialize();
|
|
7375
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7399
|
+
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7376
7400
|
return await this.multiAgentCoordinator.run(question, history);
|
|
7377
7401
|
}
|
|
7378
7402
|
const stream = this.askStream(question, history, namespace);
|
|
@@ -7407,9 +7431,9 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7407
7431
|
}
|
|
7408
7432
|
askStream(_0) {
|
|
7409
7433
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7410
|
-
var _a2;
|
|
7434
|
+
var _a2, _b;
|
|
7411
7435
|
yield new __await(this.initialize());
|
|
7412
|
-
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7436
|
+
if ((((_a2 = this.config.rag) == null ? void 0 : _a2.architecture) === "agentic" || ((_b = this.config.rag) == null ? void 0 : _b.architecture) === "multi-agent" || this.config.mcpServers && this.config.mcpServers.length > 0) && this.multiAgentCoordinator) {
|
|
7413
7437
|
const stream2 = this.multiAgentCoordinator.runStream(question, history);
|
|
7414
7438
|
try {
|
|
7415
7439
|
for (var iter = __forAwait(stream2), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -7458,7 +7482,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7458
7482
|
*/
|
|
7459
7483
|
askStreamInternal(_0) {
|
|
7460
7484
|
return __asyncGenerator(this, arguments, function* (question, history = [], namespace) {
|
|
7461
|
-
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
7485
|
+
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
7462
7486
|
yield new __await(this.initialize());
|
|
7463
7487
|
const ns = namespace != null ? namespace : this.config.projectId;
|
|
7464
7488
|
const topK = (_b = (_a2 = this.config.rag) == null ? void 0 : _a2.topK) != null ? _b : 5;
|
|
@@ -7481,13 +7505,14 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7481
7505
|
const embedStart = performance.now();
|
|
7482
7506
|
const cacheKey = `${ns}::${searchQuery}`;
|
|
7483
7507
|
const cachedVector = this.embeddingCache.get(cacheKey);
|
|
7484
|
-
const
|
|
7508
|
+
const arch = (_h = this.config.rag) == null ? void 0 : _h.architecture;
|
|
7509
|
+
const useGraph = arch !== "naive" && arch !== "retrieve-and-rerank" && this.graphDB && ((_i = this.config.rag) == null ? void 0 : _i.useGraphRetrieval);
|
|
7485
7510
|
const [strategyResult, embeddedVector] = yield new __await(Promise.all([
|
|
7486
7511
|
QueryProcessor.determineRetrievalStrategy(
|
|
7487
7512
|
searchQuery,
|
|
7488
7513
|
useGraph ? this.llmRouter.get("fast") : void 0,
|
|
7489
|
-
(
|
|
7490
|
-
(
|
|
7514
|
+
(_j = this.config.rag) == null ? void 0 : _j.graphKeywords,
|
|
7515
|
+
(_k = this.config.rag) == null ? void 0 : _k.vectorKeywords
|
|
7491
7516
|
),
|
|
7492
7517
|
// Embed immediately regardless of strategy — costs nothing if cached.
|
|
7493
7518
|
// If strategy turns out to be 'graph'-only we just won't use the vector.
|
|
@@ -7497,7 +7522,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7497
7522
|
if (!cachedVector && queryVector.length > 0) {
|
|
7498
7523
|
this.embeddingCache.set(cacheKey, queryVector);
|
|
7499
7524
|
}
|
|
7500
|
-
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((
|
|
7525
|
+
const graphData = (strategyResult === "graph" || strategyResult === "both") && this.graphDB && ((_l = this.config.rag) == null ? void 0 : _l.useGraphRetrieval) ? yield new __await(this.graphDB.query(searchQuery)) : void 0;
|
|
7501
7526
|
const hasMetadataFilter = filter.metadata && Object.keys(filter.metadata).length > 0;
|
|
7502
7527
|
const hasNumericPredicates = Array.isArray(filter.__numericPredicates) && filter.__numericPredicates.length > 0;
|
|
7503
7528
|
const wantsExhaustiveList = hasNumericPredicates || hasMetadataFilter || /\b(list|all|show|provide|give|get|browse|find|search|display)\b/i.test(question);
|
|
@@ -7510,7 +7535,8 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
7510
7535
|
const structuredSources = this.applyStructuredFilters(rawSources, filter);
|
|
7511
7536
|
let fullSources = hasNumericPredicates ? structuredSources : structuredSources.filter((m) => m.score >= scoreThreshold);
|
|
7512
7537
|
const rerankLimit = wantsExhaustiveList ? retrievalLimit : topK;
|
|
7513
|
-
|
|
7538
|
+
const useReranking = arch !== "naive" && (arch === "retrieve-and-rerank" || ((_m = this.config.rag) == null ? void 0 : _m.useReranking));
|
|
7539
|
+
if (!hasNumericPredicates && useReranking) {
|
|
7514
7540
|
fullSources = yield new __await(this.reranker.rerank(fullSources, question, rerankLimit));
|
|
7515
7541
|
} else if (!wantsExhaustiveList) {
|
|
7516
7542
|
fullSources = fullSources.slice(0, topK);
|
|
@@ -7540,7 +7566,7 @@ ${graphContext}
|
|
|
7540
7566
|
VECTOR CONTEXT:
|
|
7541
7567
|
${context}`;
|
|
7542
7568
|
}
|
|
7543
|
-
if ((
|
|
7569
|
+
if ((_o = (_n = this.config.rag) == null ? void 0 : _n.cag) == null ? void 0 : _o.enabled) {
|
|
7544
7570
|
if (!this.coldContexts.has(ns)) {
|
|
7545
7571
|
yield new __await(this.loadColdContext(ns));
|
|
7546
7572
|
}
|
|
@@ -7593,10 +7619,10 @@ ${context}`;
|
|
|
7593
7619
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
7594
7620
|
const restrictionSuffix = "\n\n(IMPORTANT: Format your response beautifully using rich Markdown! Use bolding for emphasis, headings (##) for structure, bullet points for lists, and proper line breaks between paragraphs to make it highly readable. However, NEVER generate Markdown tables, HTML figures, or text charts (the UI renders requested charts separately, so NEVER say you cannot create, display, draw, render, or provide a chart/visualization). If listing products, use simple markdown bullet points or comma-separated names. NEVER use plus signs (+) to separate product names, category names, or list items. For product description/detail questions, provide customer-facing prose only and do NOT list internal catalog fields such as Handle, Body (HTML), Vendor, Type, Tags, Published, Option, Variant, SKU, or raw metadata labels. You CAN use numbers for years/counts like 2006 or 5800, but NEVER put a dollar sign ($) before them.)";
|
|
7595
7621
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
7596
|
-
const isNativeThinking = isClaude37 && (((
|
|
7622
|
+
const isNativeThinking = isClaude37 && (((_p = this.config.llm.options) == null ? void 0 : _p.thinking) === true || ((_q = this.config.llm.options) == null ? void 0 : _q.thinking) === "enabled" || ((_r = this.config.llm.options) == null ? void 0 : _r.thinking) !== false);
|
|
7597
7623
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
7598
7624
|
const isReasoningModel = modelNameLower.includes("-r1") || modelNameLower.includes("deepseek-r1") || modelNameLower.includes("reasoning") || modelNameLower.includes("thinking");
|
|
7599
|
-
const isSimulatedThinking = !isNativeThinking && (((
|
|
7625
|
+
const isSimulatedThinking = !isNativeThinking && (((_s = this.config.llm.options) == null ? void 0 : _s.thinking) === true || ((_t = this.config.llm.options) == null ? void 0 : _t.thinking) === "enabled" || isReasoningModel && ((_u = this.config.llm.options) == null ? void 0 : _u.thinking) !== false);
|
|
7600
7626
|
let finalRestrictionSuffix = restrictionSuffix;
|
|
7601
7627
|
if (isSimulatedThinking) {
|
|
7602
7628
|
finalRestrictionSuffix += "\n\n(IMPORTANT: You must think step-by-step before answering. Write your thinking process inside a `<think>...</think>` block. Write the `<think>` block first, then follow it with your final response. Keep the thinking process thorough and detailed. Example: `<think>Thinking details here...</think>Final answer text here.`)";
|
|
@@ -7604,7 +7630,7 @@ ${context}`;
|
|
|
7604
7630
|
const hardenedHistory = [...history];
|
|
7605
7631
|
const userQuestion = { role: "user", content: question + finalRestrictionSuffix };
|
|
7606
7632
|
const messages = [...hardenedHistory, userQuestion];
|
|
7607
|
-
const systemPrompt = (
|
|
7633
|
+
const systemPrompt = (_v = this.config.llm.systemPrompt) != null ? _v : "";
|
|
7608
7634
|
const userPrompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
7609
7635
|
let fullReply = "";
|
|
7610
7636
|
let thinkingText = "";
|
|
@@ -7715,7 +7741,7 @@ ${context}`;
|
|
|
7715
7741
|
}
|
|
7716
7742
|
yield fullReply;
|
|
7717
7743
|
}
|
|
7718
|
-
const runHallucination = ((
|
|
7744
|
+
const runHallucination = ((_w = this.config.llm.options) == null ? void 0 : _w.hallucinationScoring) === true || this.config.llm.provider !== "ollama" && ((_x = this.config.llm.options) == null ? void 0 : _x.hallucinationScoring) !== false;
|
|
7719
7745
|
if (runHallucination) {
|
|
7720
7746
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context).catch(() => void 0);
|
|
7721
7747
|
}
|
|
@@ -7724,7 +7750,7 @@ ${context}`;
|
|
|
7724
7750
|
const latency = {
|
|
7725
7751
|
embedMs: Math.round(embedMs),
|
|
7726
7752
|
retrieveMs: Math.round(retrieveMs),
|
|
7727
|
-
rerankMs: ((
|
|
7753
|
+
rerankMs: arch !== "naive" && (arch === "retrieve-and-rerank" || ((_y = this.config.rag) == null ? void 0 : _y.useReranking)) ? Math.round(rerankMs) : void 0,
|
|
7728
7754
|
generateMs: Math.round(generateMs),
|
|
7729
7755
|
totalMs: Math.round(totalMs)
|
|
7730
7756
|
};
|
|
@@ -7737,7 +7763,7 @@ ${context}`;
|
|
|
7737
7763
|
totalTokens: promptTokens + completionTokens,
|
|
7738
7764
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
7739
7765
|
};
|
|
7740
|
-
const awaitHallucination = ((
|
|
7766
|
+
const awaitHallucination = ((_z = this.config.llm.options) == null ? void 0 : _z.awaitHallucination) === true;
|
|
7741
7767
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
7742
7768
|
uiTransformationPromise,
|
|
7743
7769
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -7766,7 +7792,7 @@ ${context}`;
|
|
|
7766
7792
|
hallucinationReason: hScore.reason
|
|
7767
7793
|
} : {});
|
|
7768
7794
|
const trace = buildTrace(hallucinationResult);
|
|
7769
|
-
if ((
|
|
7795
|
+
if ((_A = this.config.telemetry) == null ? void 0 : _A.enabled) {
|
|
7770
7796
|
const telemetryUrl = this.config.telemetry.url || "/api/telemetry";
|
|
7771
7797
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7772
7798
|
(async () => {
|
|
@@ -8142,6 +8168,19 @@ var LicenseVerifier = class {
|
|
|
8142
8168
|
*/
|
|
8143
8169
|
static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
|
|
8144
8170
|
const isProduction = process.env.NODE_ENV === "production";
|
|
8171
|
+
const now = Date.now();
|
|
8172
|
+
if (licenseKey) {
|
|
8173
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8174
|
+
const cached = this.cache.get(cacheKey);
|
|
8175
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
8176
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
8177
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
8178
|
+
this.cache.delete(cacheKey);
|
|
8179
|
+
} else {
|
|
8180
|
+
return cached.payload;
|
|
8181
|
+
}
|
|
8182
|
+
}
|
|
8183
|
+
}
|
|
8145
8184
|
if (!licenseKey) {
|
|
8146
8185
|
if (isProduction) {
|
|
8147
8186
|
throw new ConfigurationException(
|
|
@@ -8228,6 +8267,10 @@ var LicenseVerifier = class {
|
|
|
8228
8267
|
}
|
|
8229
8268
|
}
|
|
8230
8269
|
}
|
|
8270
|
+
if (licenseKey) {
|
|
8271
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
8272
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
8273
|
+
}
|
|
8231
8274
|
return payload;
|
|
8232
8275
|
} catch (err) {
|
|
8233
8276
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8236,7 +8279,76 @@ var LicenseVerifier = class {
|
|
|
8236
8279
|
);
|
|
8237
8280
|
}
|
|
8238
8281
|
}
|
|
8282
|
+
static async verifyIP(licenseKey) {
|
|
8283
|
+
if (!licenseKey) return;
|
|
8284
|
+
try {
|
|
8285
|
+
const parts = licenseKey.split(".");
|
|
8286
|
+
if (parts.length !== 3) return;
|
|
8287
|
+
const [, payloadB64] = parts;
|
|
8288
|
+
const payload = JSON.parse(
|
|
8289
|
+
Buffer.from(payloadB64, "base64url").toString("utf8")
|
|
8290
|
+
);
|
|
8291
|
+
const tier = (payload.tier || "").toLowerCase();
|
|
8292
|
+
if (tier === "enterprise" || tier === "custom") {
|
|
8293
|
+
return;
|
|
8294
|
+
}
|
|
8295
|
+
if (payload.ipv4 || payload.ipv6) {
|
|
8296
|
+
let currentIpv4 = "";
|
|
8297
|
+
let currentIpv6 = "";
|
|
8298
|
+
try {
|
|
8299
|
+
const res = await fetch("https://api4.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8300
|
+
const data = await res.json();
|
|
8301
|
+
currentIpv4 = data.ip;
|
|
8302
|
+
} catch (e) {
|
|
8303
|
+
}
|
|
8304
|
+
try {
|
|
8305
|
+
const res = await fetch("https://api6.ipify.org?format=json", { signal: AbortSignal.timeout(3e3) });
|
|
8306
|
+
const data = await res.json();
|
|
8307
|
+
currentIpv6 = data.ip;
|
|
8308
|
+
} catch (e) {
|
|
8309
|
+
}
|
|
8310
|
+
const localIps = [];
|
|
8311
|
+
try {
|
|
8312
|
+
const osModule = require("os");
|
|
8313
|
+
const interfaces = osModule.networkInterfaces();
|
|
8314
|
+
for (const name of Object.keys(interfaces)) {
|
|
8315
|
+
for (const iface of interfaces[name] || []) {
|
|
8316
|
+
if (!iface.internal) {
|
|
8317
|
+
localIps.push(iface.address);
|
|
8318
|
+
}
|
|
8319
|
+
}
|
|
8320
|
+
}
|
|
8321
|
+
} catch (e) {
|
|
8322
|
+
}
|
|
8323
|
+
const isIpv4Match = payload.ipv4 && (currentIpv4 === payload.ipv4 || localIps.includes(payload.ipv4));
|
|
8324
|
+
const isIpv6Match = payload.ipv6 && (currentIpv6 === payload.ipv6 || localIps.includes(payload.ipv6));
|
|
8325
|
+
if (payload.ipv4 && payload.ipv6) {
|
|
8326
|
+
if (!isIpv4Match && !isIpv6Match) {
|
|
8327
|
+
throw new Error(
|
|
8328
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}, IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
8329
|
+
);
|
|
8330
|
+
}
|
|
8331
|
+
} else if (payload.ipv4 && !isIpv4Match) {
|
|
8332
|
+
throw new Error(
|
|
8333
|
+
`License key access restricted. This license key was created for a different system (authorized IPv4: ${payload.ipv4}) and cannot be used on this machine.`
|
|
8334
|
+
);
|
|
8335
|
+
} else if (payload.ipv6 && !isIpv6Match) {
|
|
8336
|
+
throw new Error(
|
|
8337
|
+
`License key access restricted. This license key was created for a different system (authorized IPv6: ${payload.ipv6}) and cannot be used on this machine.`
|
|
8338
|
+
);
|
|
8339
|
+
}
|
|
8340
|
+
}
|
|
8341
|
+
} catch (err) {
|
|
8342
|
+
if (err.message.includes("License key access restricted")) {
|
|
8343
|
+
throw new ConfigurationException(`[Retrivora SDK] ${err.message}`);
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
}
|
|
8239
8347
|
};
|
|
8348
|
+
// A simple in-memory cache to save CPU overhead of cryptographic signature checks.
|
|
8349
|
+
LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
8350
|
+
LicenseVerifier.CACHE_TTL_MS = 60 * 1e3;
|
|
8351
|
+
// Cache verified license for 60 seconds
|
|
8240
8352
|
// Retrivora's Public Key used to verify the license key signature.
|
|
8241
8353
|
// In production, this matches the private key held by Retrivora SaaS.
|
|
8242
8354
|
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|