@retrivora-ai/rag-engine 1.0.3 → 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.
- package/dist/DocumentChunker-Dh9TvmGG.d.mts +45 -0
- package/dist/DocumentChunker-Dh9TvmGG.d.ts +45 -0
- package/dist/{RagConfig-DRJO4hGU.d.mts → RagConfig-BEmz4hVP.d.mts} +58 -1
- package/dist/{RagConfig-DRJO4hGU.d.ts → RagConfig-BEmz4hVP.d.ts} +58 -1
- package/dist/{chunk-3JR3SAWX.mjs → chunk-MWL4AGQI.mjs} +216 -108
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +218 -110
- package/dist/handlers/index.mjs +11 -3
- package/dist/index-CSfaCeux.d.ts +206 -0
- package/dist/index-DFSy0CG6.d.mts +206 -0
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +103 -89
- package/dist/index.mjs +91 -95
- package/dist/server.d.mts +45 -97
- package/dist/server.d.ts +45 -97
- package/dist/server.js +298 -225
- package/dist/server.mjs +78 -167
- package/package.json +12 -10
- package/src/components/ChatWindow.tsx +2 -2
- package/src/components/ConfigProvider.tsx +2 -2
- package/src/components/MessageBubble.tsx +2 -2
- package/src/components/SourceCard.tsx +1 -1
- package/src/components/ThemeToggle.tsx +1 -1
- package/src/config/ConfigBuilder.ts +86 -211
- package/src/config/uiConstants.ts +23 -0
- package/src/core/ConfigResolver.ts +57 -29
- package/src/core/LangChainAgent.ts +73 -40
- package/src/core/Pipeline.ts +63 -7
- package/src/core/ProviderRegistry.ts +2 -2
- package/src/core/QueryProcessor.ts +9 -8
- package/src/handlers/index.ts +138 -49
- package/src/hooks/useRagChat.ts +71 -32
- package/src/rag/EntityExtractor.ts +40 -13
- package/src/server.ts +12 -2
- package/dist/DocumentChunker-C-sCZPhi.d.mts +0 -102
- package/dist/DocumentChunker-C-sCZPhi.d.ts +0 -102
- package/dist/index-B2mutkgp.d.ts +0 -116
- package/dist/index-Bjy0es5a.d.mts +0 -116
|
@@ -190,13 +190,23 @@ function getRagConfig(env = process.env) {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// src/core/ConfigResolver.ts
|
|
193
|
+
var _cachedEnvConfig = null;
|
|
194
|
+
function getCachedEnvConfig() {
|
|
195
|
+
if (!_cachedEnvConfig) {
|
|
196
|
+
_cachedEnvConfig = getRagConfig();
|
|
197
|
+
}
|
|
198
|
+
return _cachedEnvConfig;
|
|
199
|
+
}
|
|
200
|
+
function resetConfigCache() {
|
|
201
|
+
_cachedEnvConfig = null;
|
|
202
|
+
}
|
|
193
203
|
var ConfigResolver = class {
|
|
194
204
|
/**
|
|
195
|
-
* Resolves the final configuration by merging host-provided config with defaults.
|
|
205
|
+
* Resolves the final configuration by merging host-provided config with environment defaults.
|
|
196
206
|
* @param hostConfig - Partial configuration passed from the host application.
|
|
197
207
|
*/
|
|
198
208
|
static resolve(hostConfig) {
|
|
199
|
-
const envConfig =
|
|
209
|
+
const envConfig = getCachedEnvConfig();
|
|
200
210
|
if (!hostConfig) {
|
|
201
211
|
return envConfig;
|
|
202
212
|
}
|
|
@@ -1408,25 +1418,42 @@ Text to extract from:
|
|
|
1408
1418
|
const response = await this.llm.chat([
|
|
1409
1419
|
{ role: "system", content: "You are a precise knowledge graph extraction engine. You always output valid JSON and nothing else." },
|
|
1410
1420
|
{ role: "user", content: prompt }
|
|
1411
|
-
], "", { maxTokens:
|
|
1421
|
+
], "", { maxTokens: 4096, temperature: 0.1 });
|
|
1412
1422
|
try {
|
|
1413
1423
|
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
1414
1424
|
const cleanJson = jsonMatch ? jsonMatch[0] : response.trim();
|
|
1415
1425
|
return JSON.parse(cleanJson);
|
|
1416
1426
|
} catch (e) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
const jsonMatch = partialResponse.match(/\{[\s\S]*\}/);
|
|
1422
|
-
if (jsonMatch) return JSON.parse(jsonMatch[0]);
|
|
1423
|
-
} catch (e2) {
|
|
1424
|
-
}
|
|
1427
|
+
try {
|
|
1428
|
+
const repaired = this.repairTruncatedJson(response);
|
|
1429
|
+
if (repaired) return JSON.parse(repaired);
|
|
1430
|
+
} catch (e2) {
|
|
1425
1431
|
}
|
|
1426
|
-
console.warn(
|
|
1432
|
+
console.warn(`[EntityExtractor] Failed to parse LLM response. Length: ${response.length} chars.`);
|
|
1433
|
+
console.warn("[EntityExtractor] Snippet:", response.substring(0, 100) + "...");
|
|
1427
1434
|
return { nodes: [], edges: [] };
|
|
1428
1435
|
}
|
|
1429
1436
|
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Attempts to fix JSON that was cut off mid-generation.
|
|
1439
|
+
* Strategy: Find the last valid element in an array and close the structure.
|
|
1440
|
+
*/
|
|
1441
|
+
repairTruncatedJson(json) {
|
|
1442
|
+
let text = json.trim();
|
|
1443
|
+
const startIdx = text.indexOf("{");
|
|
1444
|
+
if (startIdx === -1) return null;
|
|
1445
|
+
text = text.substring(startIdx);
|
|
1446
|
+
const lastCompleteObjectIdx = text.lastIndexOf("}");
|
|
1447
|
+
if (lastCompleteObjectIdx === -1) return null;
|
|
1448
|
+
let repaired = text.substring(0, lastCompleteObjectIdx + 1);
|
|
1449
|
+
const openBrackets = (repaired.match(/\{/g) || []).length;
|
|
1450
|
+
const closedBrackets = (repaired.match(/\}/g) || []).length;
|
|
1451
|
+
const openSquares = (repaired.match(/\[/g) || []).length;
|
|
1452
|
+
const closedSquares = (repaired.match(/\]/g) || []).length;
|
|
1453
|
+
for (let i = 0; i < openSquares - closedSquares; i++) repaired += "]";
|
|
1454
|
+
for (let i = 0; i < openBrackets - closedBrackets; i++) repaired += "}";
|
|
1455
|
+
return repaired;
|
|
1456
|
+
}
|
|
1430
1457
|
};
|
|
1431
1458
|
|
|
1432
1459
|
// src/rag/Reranker.ts
|
|
@@ -1491,14 +1518,16 @@ var LangChainAgent = class {
|
|
|
1491
1518
|
this.config = config;
|
|
1492
1519
|
}
|
|
1493
1520
|
/**
|
|
1494
|
-
* Initializes the agent with the RAG pipeline as a
|
|
1495
|
-
* Dynamically imports
|
|
1521
|
+
* Initializes the LangChain ReAct agent with the RAG pipeline as a tool.
|
|
1522
|
+
* Dynamically imports langchain so the package doesn't crash if it isn't installed.
|
|
1496
1523
|
*/
|
|
1497
1524
|
async initialize(chatModel) {
|
|
1498
1525
|
try {
|
|
1499
|
-
const { DynamicTool } = await
|
|
1500
|
-
|
|
1501
|
-
|
|
1526
|
+
const [{ DynamicTool }, { HumanMessage }, { createAgent }] = await Promise.all([
|
|
1527
|
+
import("@langchain/core/tools"),
|
|
1528
|
+
import("@langchain/core/messages"),
|
|
1529
|
+
import("langchain")
|
|
1530
|
+
]);
|
|
1502
1531
|
const searchTool = new DynamicTool({
|
|
1503
1532
|
name: "document_search",
|
|
1504
1533
|
description: "Use this tool to search through the knowledge base and document repository. Input should be a specific search query.",
|
|
@@ -1507,42 +1536,53 @@ var LangChainAgent = class {
|
|
|
1507
1536
|
return `Search Results:
|
|
1508
1537
|
${response.reply}
|
|
1509
1538
|
|
|
1510
|
-
Sources Used: ${JSON.stringify(
|
|
1539
|
+
Sources Used: ${JSON.stringify(
|
|
1540
|
+
response.sources.map((s) => s.id)
|
|
1541
|
+
)}`;
|
|
1511
1542
|
}
|
|
1512
1543
|
});
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
new MessagesPlaceholder("agent_scratchpad")
|
|
1519
|
-
]);
|
|
1520
|
-
const agent = await createOpenAIFunctionsAgent({
|
|
1521
|
-
llm: chatModel,
|
|
1522
|
-
tools,
|
|
1523
|
-
prompt
|
|
1524
|
-
});
|
|
1525
|
-
this.executor = new AgentExecutor({
|
|
1526
|
-
agent,
|
|
1527
|
-
tools
|
|
1544
|
+
this.agent = createAgent({
|
|
1545
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1546
|
+
model: chatModel,
|
|
1547
|
+
tools: [searchTool],
|
|
1548
|
+
systemPrompt: this.config.llm.systemPrompt || "You are a helpful AI assistant with access to a document search tool."
|
|
1528
1549
|
});
|
|
1550
|
+
void HumanMessage;
|
|
1529
1551
|
} catch (error) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1552
|
+
const isMissing = error instanceof Error && error.message.includes("Cannot find module");
|
|
1553
|
+
const hint = isMissing ? " Make sure 'langchain' and '@langchain/core' are installed:\n npm install langchain @langchain/core" : "";
|
|
1554
|
+
throw new Error(
|
|
1555
|
+
`[LangChainAgent] Failed to initialize.${hint}
|
|
1556
|
+
${error instanceof Error ? error.message : String(error)}`
|
|
1557
|
+
);
|
|
1532
1558
|
}
|
|
1533
1559
|
}
|
|
1534
1560
|
/**
|
|
1535
1561
|
* Run the agentic flow.
|
|
1562
|
+
*
|
|
1563
|
+
* LangChain v1.x: invoke takes `{ messages: [...] }` instead of `{ input, chat_history }`.
|
|
1564
|
+
* The agent returns `{ messages: [...] }` — the last message is the final answer.
|
|
1536
1565
|
*/
|
|
1537
1566
|
async run(input, chatHistory = []) {
|
|
1538
|
-
|
|
1567
|
+
var _a, _b, _c;
|
|
1568
|
+
if (!this.agent) {
|
|
1539
1569
|
throw new Error("[LangChainAgent] Agent not initialized. Call initialize() first.");
|
|
1540
1570
|
}
|
|
1541
|
-
const
|
|
1542
|
-
|
|
1543
|
-
|
|
1571
|
+
const { HumanMessage, AIMessage } = await import("@langchain/core/messages");
|
|
1572
|
+
const historyMessages = chatHistory.map(
|
|
1573
|
+
(m) => m.role === "user" ? new HumanMessage(m.content) : new AIMessage(m.content)
|
|
1574
|
+
);
|
|
1575
|
+
const response = await this.agent.invoke({
|
|
1576
|
+
messages: [...historyMessages, new HumanMessage(input)]
|
|
1544
1577
|
});
|
|
1545
|
-
|
|
1578
|
+
const lastMessage = (_a = response == null ? void 0 : response.messages) == null ? void 0 : _a.at(-1);
|
|
1579
|
+
if (lastMessage && typeof lastMessage.content === "string") {
|
|
1580
|
+
return lastMessage.content;
|
|
1581
|
+
}
|
|
1582
|
+
if (Array.isArray(lastMessage == null ? void 0 : lastMessage.content)) {
|
|
1583
|
+
return lastMessage.content.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
1584
|
+
}
|
|
1585
|
+
return String((_c = (_b = response == null ? void 0 : response.output) != null ? _b : response) != null ? _c : "");
|
|
1546
1586
|
}
|
|
1547
1587
|
};
|
|
1548
1588
|
|
|
@@ -1951,6 +1991,10 @@ var QueryProcessor = class {
|
|
|
1951
1991
|
}
|
|
1952
1992
|
/**
|
|
1953
1993
|
* Constructs a QueryFilter object from extracted hints.
|
|
1994
|
+
*
|
|
1995
|
+
* Note: proper nouns are extracted inside `extractQueryFieldHints` and surfaced
|
|
1996
|
+
* as field-less hints; `buildQueryFilter` adds them to `keywords` without
|
|
1997
|
+
* re-running the proper noun regex to avoid duplication.
|
|
1954
1998
|
*/
|
|
1955
1999
|
static buildQueryFilter(question, hints) {
|
|
1956
2000
|
const filter = { metadata: {}, keywords: [], queryText: question };
|
|
@@ -1958,13 +2002,11 @@ var QueryProcessor = class {
|
|
|
1958
2002
|
if (hint.field) {
|
|
1959
2003
|
filter.metadata[hint.field] = hint.value;
|
|
1960
2004
|
} else {
|
|
1961
|
-
filter.keywords.
|
|
2005
|
+
if (!filter.keywords.includes(hint.value)) {
|
|
2006
|
+
filter.keywords.push(hint.value);
|
|
2007
|
+
}
|
|
1962
2008
|
}
|
|
1963
2009
|
}
|
|
1964
|
-
for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,3}\b/g)) {
|
|
1965
|
-
const term = this.normalizeHintValue(match[0]);
|
|
1966
|
-
if (term && !filter.keywords.includes(term)) filter.keywords.push(term);
|
|
1967
|
-
}
|
|
1968
2010
|
if (Object.keys(filter.metadata || {}).length === 0) delete filter.metadata;
|
|
1969
2011
|
if (filter.keywords && filter.keywords.length === 0) delete filter.keywords;
|
|
1970
2012
|
return filter;
|
|
@@ -1972,10 +2014,40 @@ var QueryProcessor = class {
|
|
|
1972
2014
|
};
|
|
1973
2015
|
|
|
1974
2016
|
// src/core/Pipeline.ts
|
|
2017
|
+
var LRUEmbeddingCache = class {
|
|
2018
|
+
constructor(maxSize = 500) {
|
|
2019
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
2020
|
+
this.maxSize = maxSize;
|
|
2021
|
+
}
|
|
2022
|
+
get(key) {
|
|
2023
|
+
const value = this.cache.get(key);
|
|
2024
|
+
if (value !== void 0) {
|
|
2025
|
+
this.cache.delete(key);
|
|
2026
|
+
this.cache.set(key, value);
|
|
2027
|
+
}
|
|
2028
|
+
return value;
|
|
2029
|
+
}
|
|
2030
|
+
set(key, value) {
|
|
2031
|
+
if (this.cache.has(key)) {
|
|
2032
|
+
this.cache.delete(key);
|
|
2033
|
+
} else if (this.cache.size >= this.maxSize) {
|
|
2034
|
+
const oldestKey = this.cache.keys().next().value;
|
|
2035
|
+
if (oldestKey !== void 0) this.cache.delete(oldestKey);
|
|
2036
|
+
}
|
|
2037
|
+
this.cache.set(key, value);
|
|
2038
|
+
}
|
|
2039
|
+
clear() {
|
|
2040
|
+
this.cache.clear();
|
|
2041
|
+
}
|
|
2042
|
+
get size() {
|
|
2043
|
+
return this.cache.size;
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
1975
2046
|
var Pipeline = class {
|
|
1976
2047
|
constructor(config) {
|
|
1977
2048
|
this.config = config;
|
|
1978
|
-
|
|
2049
|
+
/** LRU-bounded cache: avoids re-embedding identical queries within the same process. */
|
|
2050
|
+
this.embeddingCache = new LRUEmbeddingCache(500);
|
|
1979
2051
|
this.initialised = false;
|
|
1980
2052
|
var _a, _b, _c, _d, _e;
|
|
1981
2053
|
this.chunker = new DocumentChunker(
|
|
@@ -2063,6 +2135,7 @@ var Pipeline = class {
|
|
|
2063
2135
|
}
|
|
2064
2136
|
/**
|
|
2065
2137
|
* Step 2: Generate embeddings for chunks with retry logic.
|
|
2138
|
+
* Uses batchEmbed when available for efficiency; falls back to sequential embedding.
|
|
2066
2139
|
*/
|
|
2067
2140
|
async processEmbeddings(chunks) {
|
|
2068
2141
|
const embedBatchOptions = {
|
|
@@ -2076,7 +2149,9 @@ var Pipeline = class {
|
|
|
2076
2149
|
embedBatchOptions
|
|
2077
2150
|
);
|
|
2078
2151
|
if (vectors.length !== chunks.length) {
|
|
2079
|
-
throw new Error(
|
|
2152
|
+
throw new Error(
|
|
2153
|
+
`[Pipeline] Embedding mismatch: got ${vectors.length} vectors for ${chunks.length} chunks. Check embedding provider logs for individual chunk failures.`
|
|
2154
|
+
);
|
|
2080
2155
|
}
|
|
2081
2156
|
return vectors;
|
|
2082
2157
|
}
|
|
@@ -2230,6 +2305,7 @@ ${context}`;
|
|
|
2230
2305
|
}
|
|
2231
2306
|
/**
|
|
2232
2307
|
* Universal retrieval method combining all enabled providers.
|
|
2308
|
+
* Uses an LRU-bounded embedding cache to avoid re-embedding the same query.
|
|
2233
2309
|
*/
|
|
2234
2310
|
async retrieve(query, options) {
|
|
2235
2311
|
var _a, _b, _c;
|
|
@@ -2262,10 +2338,13 @@ ${history.map((m) => `${m.role}: ${m.content}`).join("\n")}
|
|
|
2262
2338
|
New Question: ${question}
|
|
2263
2339
|
|
|
2264
2340
|
Optimized Search Query:`;
|
|
2265
|
-
const rewrite = await this.llmProvider.chat(
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2341
|
+
const rewrite = await this.llmProvider.chat(
|
|
2342
|
+
[
|
|
2343
|
+
{ role: "system", content: "You are an assistant that optimizes search queries for RAG systems." },
|
|
2344
|
+
{ role: "user", content: prompt }
|
|
2345
|
+
],
|
|
2346
|
+
""
|
|
2347
|
+
);
|
|
2269
2348
|
return rewrite.trim() || question;
|
|
2270
2349
|
}
|
|
2271
2350
|
};
|
|
@@ -2484,8 +2563,35 @@ var DocumentParser = class {
|
|
|
2484
2563
|
};
|
|
2485
2564
|
|
|
2486
2565
|
// src/handlers/index.ts
|
|
2487
|
-
function
|
|
2488
|
-
|
|
2566
|
+
function sseFrame(payload) {
|
|
2567
|
+
return `data: ${JSON.stringify(payload)}
|
|
2568
|
+
|
|
2569
|
+
`;
|
|
2570
|
+
}
|
|
2571
|
+
function sseTextFrame(text) {
|
|
2572
|
+
return `data: ${JSON.stringify({ type: "text", text })}
|
|
2573
|
+
|
|
2574
|
+
`;
|
|
2575
|
+
}
|
|
2576
|
+
function sseMetaFrame(meta) {
|
|
2577
|
+
return `data: ${JSON.stringify(__spreadValues({ type: "metadata" }, meta != null ? meta : {}))}
|
|
2578
|
+
|
|
2579
|
+
`;
|
|
2580
|
+
}
|
|
2581
|
+
function sseErrorFrame(message) {
|
|
2582
|
+
return `data: ${JSON.stringify({ type: "error", error: message })}
|
|
2583
|
+
|
|
2584
|
+
`;
|
|
2585
|
+
}
|
|
2586
|
+
var SSE_HEADERS = {
|
|
2587
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
2588
|
+
"Cache-Control": "no-cache, no-transform",
|
|
2589
|
+
Connection: "keep-alive",
|
|
2590
|
+
"X-Accel-Buffering": "no"
|
|
2591
|
+
// Disable Nginx buffering for streaming
|
|
2592
|
+
};
|
|
2593
|
+
function createChatHandler(configOrPlugin) {
|
|
2594
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2489
2595
|
return async function POST(req) {
|
|
2490
2596
|
try {
|
|
2491
2597
|
const body = await req.json();
|
|
@@ -2501,67 +2607,64 @@ function createChatHandler(config) {
|
|
|
2501
2607
|
}
|
|
2502
2608
|
};
|
|
2503
2609
|
}
|
|
2504
|
-
function createStreamHandler(
|
|
2505
|
-
const plugin = new VectorPlugin(
|
|
2610
|
+
function createStreamHandler(configOrPlugin) {
|
|
2611
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2506
2612
|
return async function POST(req) {
|
|
2613
|
+
let body;
|
|
2507
2614
|
try {
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2615
|
+
body = await req.json();
|
|
2616
|
+
} catch (e) {
|
|
2617
|
+
return new Response(JSON.stringify({ error: "Invalid JSON body" }), {
|
|
2618
|
+
status: 400,
|
|
2619
|
+
headers: { "Content-Type": "application/json" }
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
const { message, history = [], namespace } = body;
|
|
2623
|
+
if (!(message == null ? void 0 : message.trim())) {
|
|
2624
|
+
return new Response(JSON.stringify({ error: "message is required" }), {
|
|
2625
|
+
status: 400,
|
|
2626
|
+
headers: { "Content-Type": "application/json" }
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
const encoder = new TextEncoder();
|
|
2630
|
+
const stream = new ReadableStream({
|
|
2631
|
+
async start(controller) {
|
|
2632
|
+
const enqueue = (text) => controller.enqueue(encoder.encode(text));
|
|
2633
|
+
try {
|
|
2634
|
+
const pipelineStream = plugin.chatStream(message, history, namespace);
|
|
2513
2635
|
try {
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
} else {
|
|
2521
|
-
controller.enqueue(encoder.encode(`
|
|
2522
|
-
|
|
2523
|
-
__METADATA__${JSON.stringify(chunk)}`));
|
|
2524
|
-
}
|
|
2636
|
+
for (var iter = __forAwait(pipelineStream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
2637
|
+
const chunk = temp.value;
|
|
2638
|
+
if (typeof chunk === "string") {
|
|
2639
|
+
enqueue(sseTextFrame(chunk));
|
|
2640
|
+
} else {
|
|
2641
|
+
enqueue(sseMetaFrame(chunk));
|
|
2525
2642
|
}
|
|
2526
|
-
}
|
|
2527
|
-
|
|
2643
|
+
}
|
|
2644
|
+
} catch (temp) {
|
|
2645
|
+
error = [temp];
|
|
2646
|
+
} finally {
|
|
2647
|
+
try {
|
|
2648
|
+
more && (temp = iter.return) && await temp.call(iter);
|
|
2528
2649
|
} finally {
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
} finally {
|
|
2532
|
-
if (error)
|
|
2533
|
-
throw error[0];
|
|
2534
|
-
}
|
|
2650
|
+
if (error)
|
|
2651
|
+
throw error[0];
|
|
2535
2652
|
}
|
|
2536
|
-
controller.close();
|
|
2537
|
-
} catch (streamError) {
|
|
2538
|
-
console.error("[createStreamHandler] Stream processing error:", streamError);
|
|
2539
|
-
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
2540
|
-
controller.enqueue(encoder.encode(`
|
|
2541
|
-
|
|
2542
|
-
__ERROR__${JSON.stringify({ error: errorMessage })}`));
|
|
2543
|
-
controller.close();
|
|
2544
2653
|
}
|
|
2654
|
+
} catch (streamError) {
|
|
2655
|
+
const errorMessage = streamError instanceof Error ? streamError.message : String(streamError);
|
|
2656
|
+
console.error("[createStreamHandler] Stream error:", streamError);
|
|
2657
|
+
enqueue(sseErrorFrame(errorMessage));
|
|
2658
|
+
} finally {
|
|
2659
|
+
controller.close();
|
|
2545
2660
|
}
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
"Content-Type": "text/event-stream",
|
|
2550
|
-
"Cache-Control": "no-cache",
|
|
2551
|
-
"Connection": "keep-alive"
|
|
2552
|
-
}
|
|
2553
|
-
});
|
|
2554
|
-
} catch (err) {
|
|
2555
|
-
const message = err instanceof Error ? err.message : "Internal server error";
|
|
2556
|
-
return new Response(JSON.stringify({ error: message }), {
|
|
2557
|
-
status: 500,
|
|
2558
|
-
headers: { "Content-Type": "application/json" }
|
|
2559
|
-
});
|
|
2560
|
-
}
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
return new Response(stream, { headers: SSE_HEADERS });
|
|
2561
2664
|
};
|
|
2562
2665
|
}
|
|
2563
|
-
function createIngestHandler(
|
|
2564
|
-
const plugin = new VectorPlugin(
|
|
2666
|
+
function createIngestHandler(configOrPlugin) {
|
|
2667
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2565
2668
|
return async function POST(req) {
|
|
2566
2669
|
try {
|
|
2567
2670
|
const body = await req.json();
|
|
@@ -2577,8 +2680,8 @@ function createIngestHandler(config) {
|
|
|
2577
2680
|
}
|
|
2578
2681
|
};
|
|
2579
2682
|
}
|
|
2580
|
-
function createHealthHandler(
|
|
2581
|
-
const plugin = new VectorPlugin(
|
|
2683
|
+
function createHealthHandler(configOrPlugin) {
|
|
2684
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2582
2685
|
return async function GET() {
|
|
2583
2686
|
try {
|
|
2584
2687
|
const health = await plugin.checkHealth();
|
|
@@ -2594,8 +2697,8 @@ function createHealthHandler(config) {
|
|
|
2594
2697
|
}
|
|
2595
2698
|
};
|
|
2596
2699
|
}
|
|
2597
|
-
function createUploadHandler(
|
|
2598
|
-
const plugin = new VectorPlugin(
|
|
2700
|
+
function createUploadHandler(configOrPlugin) {
|
|
2701
|
+
const plugin = configOrPlugin instanceof VectorPlugin ? configOrPlugin : new VectorPlugin(configOrPlugin);
|
|
2599
2702
|
return async function POST(req) {
|
|
2600
2703
|
try {
|
|
2601
2704
|
const formData = await req.formData();
|
|
@@ -2630,6 +2733,7 @@ function createUploadHandler(config) {
|
|
|
2630
2733
|
|
|
2631
2734
|
export {
|
|
2632
2735
|
getRagConfig,
|
|
2736
|
+
resetConfigCache,
|
|
2633
2737
|
ConfigResolver,
|
|
2634
2738
|
OpenAIProvider,
|
|
2635
2739
|
AnthropicProvider,
|
|
@@ -2648,6 +2752,10 @@ export {
|
|
|
2648
2752
|
ProviderHealthCheck,
|
|
2649
2753
|
VectorPlugin,
|
|
2650
2754
|
DocumentParser,
|
|
2755
|
+
sseFrame,
|
|
2756
|
+
sseTextFrame,
|
|
2757
|
+
sseMetaFrame,
|
|
2758
|
+
sseErrorFrame,
|
|
2651
2759
|
createChatHandler,
|
|
2652
2760
|
createStreamHandler,
|
|
2653
2761
|
createIngestHandler,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler,
|
|
1
|
+
import '../RagConfig-BEmz4hVP.mjs';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-DFSy0CG6.mjs';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler,
|
|
1
|
+
import '../RagConfig-BEmz4hVP.js';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-CSfaCeux.js';
|
|
3
3
|
import 'next/server';
|