@robthepcguy/rag-vault 1.0.0
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/LICENSE +24 -0
- package/README.md +421 -0
- package/dist/bin/install-skills.d.ts +20 -0
- package/dist/bin/install-skills.d.ts.map +1 -0
- package/dist/bin/install-skills.js +196 -0
- package/dist/bin/install-skills.js.map +1 -0
- package/dist/chunker/index.d.ts +11 -0
- package/dist/chunker/index.d.ts.map +1 -0
- package/dist/chunker/index.js +6 -0
- package/dist/chunker/index.js.map +1 -0
- package/dist/chunker/semantic-chunker.d.ts +96 -0
- package/dist/chunker/semantic-chunker.d.ts.map +1 -0
- package/dist/chunker/semantic-chunker.js +267 -0
- package/dist/chunker/semantic-chunker.js.map +1 -0
- package/dist/chunker/sentence-splitter.d.ts +16 -0
- package/dist/chunker/sentence-splitter.d.ts.map +1 -0
- package/dist/chunker/sentence-splitter.js +114 -0
- package/dist/chunker/sentence-splitter.js.map +1 -0
- package/dist/embedder/index.d.ts +55 -0
- package/dist/embedder/index.d.ts.map +1 -0
- package/dist/embedder/index.js +146 -0
- package/dist/embedder/index.js.map +1 -0
- package/dist/errors/index.d.ts +73 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +170 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/html-parser.d.ts +14 -0
- package/dist/parser/html-parser.d.ts.map +1 -0
- package/dist/parser/html-parser.js +99 -0
- package/dist/parser/html-parser.js.map +1 -0
- package/dist/parser/index.d.ts +144 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +446 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/pdf-filter.d.ts +89 -0
- package/dist/parser/pdf-filter.d.ts.map +1 -0
- package/dist/parser/pdf-filter.js +304 -0
- package/dist/parser/pdf-filter.js.map +1 -0
- package/dist/server/index.d.ts +144 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +518 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/raw-data-utils.d.ts +81 -0
- package/dist/server/raw-data-utils.d.ts.map +1 -0
- package/dist/server/raw-data-utils.js +196 -0
- package/dist/server/raw-data-utils.js.map +1 -0
- package/dist/server/schemas.d.ts +186 -0
- package/dist/server/schemas.d.ts.map +1 -0
- package/dist/server/schemas.js +99 -0
- package/dist/server/schemas.js.map +1 -0
- package/dist/utils/config-parsers.d.ts +14 -0
- package/dist/utils/config-parsers.d.ts.map +1 -0
- package/dist/utils/config-parsers.js +47 -0
- package/dist/utils/config-parsers.js.map +1 -0
- package/dist/utils/config.d.ts +37 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +52 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/logger.d.ts +36 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +64 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/math.d.ts +34 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +73 -0
- package/dist/utils/math.js.map +1 -0
- package/dist/utils/process-handlers.d.ts +26 -0
- package/dist/utils/process-handlers.d.ts.map +1 -0
- package/dist/utils/process-handlers.js +69 -0
- package/dist/utils/process-handlers.js.map +1 -0
- package/dist/vectordb/index.d.ts +210 -0
- package/dist/vectordb/index.d.ts.map +1 -0
- package/dist/vectordb/index.js +613 -0
- package/dist/vectordb/index.js.map +1 -0
- package/dist/web/api-routes.d.ts +9 -0
- package/dist/web/api-routes.d.ts.map +1 -0
- package/dist/web/api-routes.js +127 -0
- package/dist/web/api-routes.js.map +1 -0
- package/dist/web/config-routes.d.ts +7 -0
- package/dist/web/config-routes.d.ts.map +1 -0
- package/dist/web/config-routes.js +54 -0
- package/dist/web/config-routes.js.map +1 -0
- package/dist/web/database-manager.d.ts +130 -0
- package/dist/web/database-manager.d.ts.map +1 -0
- package/dist/web/database-manager.js +382 -0
- package/dist/web/database-manager.js.map +1 -0
- package/dist/web/http-server.d.ts +28 -0
- package/dist/web/http-server.d.ts.map +1 -0
- package/dist/web/http-server.js +311 -0
- package/dist/web/http-server.js.map +1 -0
- package/dist/web/index.d.ts +3 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +114 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/middleware/async-handler.d.ts +17 -0
- package/dist/web/middleware/async-handler.d.ts.map +1 -0
- package/dist/web/middleware/async-handler.js +26 -0
- package/dist/web/middleware/async-handler.js.map +1 -0
- package/dist/web/middleware/auth.d.ts +22 -0
- package/dist/web/middleware/auth.d.ts.map +1 -0
- package/dist/web/middleware/auth.js +81 -0
- package/dist/web/middleware/auth.js.map +1 -0
- package/dist/web/middleware/error-handler.d.ts +36 -0
- package/dist/web/middleware/error-handler.d.ts.map +1 -0
- package/dist/web/middleware/error-handler.js +68 -0
- package/dist/web/middleware/error-handler.js.map +1 -0
- package/dist/web/middleware/index.d.ts +6 -0
- package/dist/web/middleware/index.d.ts.map +1 -0
- package/dist/web/middleware/index.js +19 -0
- package/dist/web/middleware/index.js.map +1 -0
- package/dist/web/middleware/rate-limit.d.ts +38 -0
- package/dist/web/middleware/rate-limit.d.ts.map +1 -0
- package/dist/web/middleware/rate-limit.js +116 -0
- package/dist/web/middleware/rate-limit.js.map +1 -0
- package/dist/web/middleware/request-logger.d.ts +52 -0
- package/dist/web/middleware/request-logger.d.ts.map +1 -0
- package/dist/web/middleware/request-logger.js +74 -0
- package/dist/web/middleware/request-logger.js.map +1 -0
- package/dist/web/types.d.ts +6 -0
- package/dist/web/types.d.ts.map +1 -0
- package/dist/web/types.js +4 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +135 -0
- package/skills/rag-vault/SKILL.md +111 -0
- package/skills/rag-vault/references/html-ingestion.md +73 -0
- package/skills/rag-vault/references/query-optimization.md +57 -0
- package/skills/rag-vault/references/result-refinement.md +54 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// REST API routes for web frontend
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createApiRouter = createApiRouter;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const express_1 = require("express");
|
|
10
|
+
const index_js_1 = require("../errors/index.js");
|
|
11
|
+
const index_js_2 = require("./middleware/index.js");
|
|
12
|
+
/**
|
|
13
|
+
* Extract text from a RAG server response with proper bounds checking
|
|
14
|
+
* @throws RAGError if the response format is invalid
|
|
15
|
+
*/
|
|
16
|
+
function extractResultText(result) {
|
|
17
|
+
if (!result.content || !Array.isArray(result.content) || result.content.length === 0) {
|
|
18
|
+
throw new index_js_1.RAGError('Malformed server response: missing content array', {
|
|
19
|
+
statusCode: 500,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const firstContent = result.content[0];
|
|
23
|
+
if (!firstContent || typeof firstContent.text !== 'string') {
|
|
24
|
+
throw new index_js_1.RAGError('Malformed server response: missing text in content', {
|
|
25
|
+
statusCode: 500,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return firstContent.text;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create API router with all endpoints
|
|
32
|
+
* @param serverOrAccessor - RAGServer instance or accessor function
|
|
33
|
+
*/
|
|
34
|
+
function createApiRouter(serverOrAccessor) {
|
|
35
|
+
const router = (0, express_1.Router)();
|
|
36
|
+
// Helper to get server (supports both direct instance and accessor function)
|
|
37
|
+
const getServer = () => {
|
|
38
|
+
if (typeof serverOrAccessor === 'function') {
|
|
39
|
+
return serverOrAccessor();
|
|
40
|
+
}
|
|
41
|
+
return serverOrAccessor;
|
|
42
|
+
};
|
|
43
|
+
// POST /api/v1/search - Search documents
|
|
44
|
+
router.post('/search', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
45
|
+
const { query, limit } = req.body;
|
|
46
|
+
if (!query || typeof query !== 'string') {
|
|
47
|
+
throw new index_js_1.ValidationError('Query is required and must be a string');
|
|
48
|
+
}
|
|
49
|
+
const queryInput = { query };
|
|
50
|
+
if (limit !== undefined) {
|
|
51
|
+
queryInput.limit = limit;
|
|
52
|
+
}
|
|
53
|
+
const server = getServer();
|
|
54
|
+
const result = await server.handleQueryDocuments(queryInput);
|
|
55
|
+
const data = JSON.parse(extractResultText(result));
|
|
56
|
+
res.json({ results: data });
|
|
57
|
+
}));
|
|
58
|
+
// POST /api/v1/files/upload - Upload files (multipart)
|
|
59
|
+
router.post('/files/upload', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
60
|
+
// File is attached by multer middleware
|
|
61
|
+
const file = req.file;
|
|
62
|
+
if (!file) {
|
|
63
|
+
throw new index_js_1.ValidationError('No file uploaded');
|
|
64
|
+
}
|
|
65
|
+
// Use the uploaded file path (convert to absolute)
|
|
66
|
+
const server = getServer();
|
|
67
|
+
const absolutePath = node_path_1.default.resolve(file.path);
|
|
68
|
+
const result = await server.handleIngestFile({ filePath: absolutePath });
|
|
69
|
+
const data = JSON.parse(extractResultText(result));
|
|
70
|
+
res.json(data);
|
|
71
|
+
}));
|
|
72
|
+
// POST /api/v1/data - Ingest content strings
|
|
73
|
+
router.post('/data', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
74
|
+
const { content, metadata } = req.body;
|
|
75
|
+
if (!content || typeof content !== 'string') {
|
|
76
|
+
throw new index_js_1.ValidationError('Content is required and must be a string');
|
|
77
|
+
}
|
|
78
|
+
if (!metadata || !metadata.source || !metadata.format) {
|
|
79
|
+
throw new index_js_1.ValidationError('Metadata with source and format is required');
|
|
80
|
+
}
|
|
81
|
+
const server = getServer();
|
|
82
|
+
const result = await server.handleIngestData({ content, metadata });
|
|
83
|
+
const data = JSON.parse(extractResultText(result));
|
|
84
|
+
res.json(data);
|
|
85
|
+
}));
|
|
86
|
+
// GET /api/v1/files - List ingested files
|
|
87
|
+
router.get('/files', (0, index_js_2.asyncHandler)(async (_req, res) => {
|
|
88
|
+
const server = getServer();
|
|
89
|
+
const result = await server.handleListFiles();
|
|
90
|
+
const data = JSON.parse(extractResultText(result));
|
|
91
|
+
res.json({ files: data });
|
|
92
|
+
}));
|
|
93
|
+
// DELETE /api/v1/files - Delete file/source
|
|
94
|
+
router.delete('/files', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
95
|
+
const { filePath, source } = req.body;
|
|
96
|
+
if (!filePath && !source) {
|
|
97
|
+
throw new index_js_1.ValidationError('Either filePath or source is required');
|
|
98
|
+
}
|
|
99
|
+
const deleteInput = {};
|
|
100
|
+
if (filePath !== undefined) {
|
|
101
|
+
deleteInput.filePath = filePath;
|
|
102
|
+
}
|
|
103
|
+
if (source !== undefined) {
|
|
104
|
+
deleteInput.source = source;
|
|
105
|
+
}
|
|
106
|
+
const server = getServer();
|
|
107
|
+
const result = await server.handleDeleteFile(deleteInput);
|
|
108
|
+
const data = JSON.parse(extractResultText(result));
|
|
109
|
+
res.json(data);
|
|
110
|
+
}));
|
|
111
|
+
// GET /api/v1/status - System status
|
|
112
|
+
router.get('/status', (0, index_js_2.asyncHandler)(async (_req, res) => {
|
|
113
|
+
const server = getServer();
|
|
114
|
+
const result = await server.handleStatus();
|
|
115
|
+
const data = JSON.parse(extractResultText(result));
|
|
116
|
+
res.json(data);
|
|
117
|
+
}));
|
|
118
|
+
// GET /api/v1/health - Lightweight health check for load balancers
|
|
119
|
+
router.get('/health', (_req, res) => {
|
|
120
|
+
res.json({
|
|
121
|
+
status: 'ok',
|
|
122
|
+
timestamp: new Date().toISOString(),
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return router;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=api-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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nE,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;QACrD,GAAG,CAAC,IAAI,CAAC;YACP,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Router } from 'express';
|
|
2
|
+
import type { DatabaseManager } from './database-manager.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create config API router with all endpoints
|
|
5
|
+
*/
|
|
6
|
+
export declare function createConfigRouter(dbManager: DatabaseManager): Router;
|
|
7
|
+
//# sourceMappingURL=config-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-routes.d.ts","sourceRoot":"","sources":["../../src/web/config-routes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAA;AAGxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAyB5D;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAqErE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// REST API routes for database configuration
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createConfigRouter = createConfigRouter;
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const index_js_1 = require("../errors/index.js");
|
|
7
|
+
const index_js_2 = require("./middleware/index.js");
|
|
8
|
+
/**
|
|
9
|
+
* Create config API router with all endpoints
|
|
10
|
+
*/
|
|
11
|
+
function createConfigRouter(dbManager) {
|
|
12
|
+
const router = (0, express_1.Router)();
|
|
13
|
+
// GET /api/v1/config/current - Get current database configuration
|
|
14
|
+
router.get('/current', (0, index_js_2.asyncHandler)(async (_req, res) => {
|
|
15
|
+
const config = await dbManager.getCurrentConfig();
|
|
16
|
+
res.json(config);
|
|
17
|
+
}));
|
|
18
|
+
// GET /api/v1/config/databases - List recent databases
|
|
19
|
+
router.get('/databases', (0, index_js_2.asyncHandler)(async (_req, res) => {
|
|
20
|
+
const databases = await dbManager.getRecentDatabases();
|
|
21
|
+
res.json({ databases });
|
|
22
|
+
}));
|
|
23
|
+
// POST /api/v1/config/databases/switch - Switch to different database
|
|
24
|
+
router.post('/databases/switch', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
25
|
+
const { dbPath } = req.body;
|
|
26
|
+
if (!dbPath || typeof dbPath !== 'string') {
|
|
27
|
+
throw new index_js_1.ValidationError('dbPath is required and must be a string');
|
|
28
|
+
}
|
|
29
|
+
await dbManager.switchDatabase(dbPath);
|
|
30
|
+
const config = await dbManager.getCurrentConfig();
|
|
31
|
+
res.json({ success: true, config });
|
|
32
|
+
}));
|
|
33
|
+
// POST /api/v1/config/databases/create - Create new database
|
|
34
|
+
router.post('/databases/create', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
35
|
+
const { dbPath, name } = req.body;
|
|
36
|
+
if (!dbPath || typeof dbPath !== 'string') {
|
|
37
|
+
throw new index_js_1.ValidationError('dbPath is required and must be a string');
|
|
38
|
+
}
|
|
39
|
+
await dbManager.createDatabase({ dbPath, name });
|
|
40
|
+
const config = await dbManager.getCurrentConfig();
|
|
41
|
+
res.json({ success: true, config });
|
|
42
|
+
}));
|
|
43
|
+
// POST /api/v1/config/databases/scan - Scan directory for databases
|
|
44
|
+
router.post('/databases/scan', (0, index_js_2.asyncHandler)(async (req, res) => {
|
|
45
|
+
const { scanPath } = req.body;
|
|
46
|
+
if (!scanPath || typeof scanPath !== 'string') {
|
|
47
|
+
throw new index_js_1.ValidationError('scanPath is required and must be a string');
|
|
48
|
+
}
|
|
49
|
+
const databases = await dbManager.scanForDatabases(scanPath);
|
|
50
|
+
res.json({ databases });
|
|
51
|
+
}));
|
|
52
|
+
return router;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=config-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-routes.js","sourceRoot":"","sources":["../../src/web/config-routes.ts"],"names":[],"mappings":";AAAA,6CAA6C;;AAiC7C,gDAqEC;AAnGD,qCAAgD;AAChD,iDAAoD;AAEpD,oDAAoD;AAwBpD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,SAA0B;IAC3D,MAAM,MAAM,GAAG,IAAA,gBAAY,GAAE,CAAA;IAE7B,kEAAkE;IAClE,MAAM,CAAC,GAAG,CACR,UAAU,EACV,IAAA,uBAAY,EAAC,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,EAAE;QAClD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,gBAAgB,EAAE,CAAA;QACjD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAClB,CAAC,CAAC,CACH,CAAA;IAED,uDAAuD;IACvD,MAAM,CAAC,GAAG,CACR,YAAY,EACZ,IAAA,uBAAY,EAAC,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,EAAE;QAClD,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,kBAAkB,EAAE,CAAA;QACtD,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;IACzB,CAAC,CAAC,CACH,CAAA;IAED,sEAAsE;IACtE,MAAM,CAAC,IAAI,CACT,mBAAmB,EACnB,IAAA,uBAAY,EAAC,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;QACjD,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAA6B,CAAA;QAEpD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC1C,MAAM,IAAI,0BAAe,CAAC,yCAAyC,CAAC,CAAA;QACtE,CAAC;QAED,MAAM,SAAS,CAAC,cAAc,CAAC,MA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,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { RAGServer, RAGServerConfig } from '../server/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Database entry in recent databases list
|
|
4
|
+
*/
|
|
5
|
+
export interface DatabaseEntry {
|
|
6
|
+
/** Absolute path to the database directory */
|
|
7
|
+
path: string;
|
|
8
|
+
/** Human-readable name (derived from path) */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Last access timestamp (ISO 8601) */
|
|
11
|
+
lastAccessed: string;
|
|
12
|
+
/** Model name used with this database */
|
|
13
|
+
modelName?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Current database configuration (extended with stats)
|
|
17
|
+
*/
|
|
18
|
+
export interface CurrentDatabaseConfig {
|
|
19
|
+
/** Database path */
|
|
20
|
+
dbPath: string;
|
|
21
|
+
/** Model name */
|
|
22
|
+
modelName: string;
|
|
23
|
+
/** Human-readable database name */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Document count */
|
|
26
|
+
documentCount: number;
|
|
27
|
+
/** Chunk count */
|
|
28
|
+
chunkCount: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create database options
|
|
32
|
+
*/
|
|
33
|
+
export interface CreateDatabaseOptions {
|
|
34
|
+
/** Path where to create the database */
|
|
35
|
+
dbPath: string;
|
|
36
|
+
/** Optional custom name */
|
|
37
|
+
name?: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Scan result for a discovered database
|
|
41
|
+
*/
|
|
42
|
+
export interface ScannedDatabase {
|
|
43
|
+
/** Absolute path to the database */
|
|
44
|
+
path: string;
|
|
45
|
+
/** Human-readable name */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Whether this database is already in recent list */
|
|
48
|
+
isKnown: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* DatabaseManager handles RAG database lifecycle management
|
|
52
|
+
*
|
|
53
|
+
* Responsibilities:
|
|
54
|
+
* - Track current database connection
|
|
55
|
+
* - Hot-swap between databases
|
|
56
|
+
* - Persist recent databases list
|
|
57
|
+
* - Discover databases by scanning directories
|
|
58
|
+
*/
|
|
59
|
+
export declare class DatabaseManager {
|
|
60
|
+
private currentServer;
|
|
61
|
+
private currentConfig;
|
|
62
|
+
private serverFactory;
|
|
63
|
+
private baseConfig;
|
|
64
|
+
private switchPromise;
|
|
65
|
+
constructor(serverFactory: (config: RAGServerConfig) => RAGServer, baseConfig: Omit<RAGServerConfig, 'dbPath'>);
|
|
66
|
+
/**
|
|
67
|
+
* Initialize with a database path
|
|
68
|
+
*/
|
|
69
|
+
initialize(dbPath: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get current RAG server instance
|
|
72
|
+
*/
|
|
73
|
+
getServer(): RAGServer;
|
|
74
|
+
/**
|
|
75
|
+
* Get current database configuration with stats
|
|
76
|
+
*/
|
|
77
|
+
getCurrentConfig(): Promise<CurrentDatabaseConfig | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Switch to a different database
|
|
80
|
+
*
|
|
81
|
+
* Uses promise-based mutex to prevent race conditions from concurrent switch attempts.
|
|
82
|
+
*/
|
|
83
|
+
switchDatabase(newDbPath: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Internal method to perform the actual database switch
|
|
86
|
+
*/
|
|
87
|
+
private performSwitch;
|
|
88
|
+
/**
|
|
89
|
+
* Create a new database
|
|
90
|
+
*/
|
|
91
|
+
createDatabase(options: CreateDatabaseOptions): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Switch to a new (possibly empty) database
|
|
94
|
+
*
|
|
95
|
+
* Uses promise-based mutex to prevent race conditions from concurrent switch attempts.
|
|
96
|
+
*/
|
|
97
|
+
private switchToNewDatabase;
|
|
98
|
+
/**
|
|
99
|
+
* Internal method to perform the actual switch to a new database
|
|
100
|
+
*/
|
|
101
|
+
private performSwitchToNew;
|
|
102
|
+
/**
|
|
103
|
+
* Get list of recent databases
|
|
104
|
+
*
|
|
105
|
+
* Handles errors appropriately:
|
|
106
|
+
* - File not found: Normal case, returns empty array
|
|
107
|
+
* - Parse/validation error: Logs error but returns empty array to allow recovery
|
|
108
|
+
*/
|
|
109
|
+
getRecentDatabases(): Promise<DatabaseEntry[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Scan a directory for LanceDB databases
|
|
112
|
+
*
|
|
113
|
+
* Security: Only scans within allowed roots (ALLOWED_SCAN_ROOTS env var or home directory)
|
|
114
|
+
* to prevent path traversal attacks.
|
|
115
|
+
*/
|
|
116
|
+
scanForDatabases(scanPath: string): Promise<ScannedDatabase[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Add a database to recent list
|
|
119
|
+
*/
|
|
120
|
+
private addToRecent;
|
|
121
|
+
/**
|
|
122
|
+
* Derive a human-readable name from a path
|
|
123
|
+
*/
|
|
124
|
+
private getNameFromPath;
|
|
125
|
+
/**
|
|
126
|
+
* Ensure config directory exists
|
|
127
|
+
*/
|
|
128
|
+
private ensureConfigDir;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=database-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-manager.d.ts","sourceRoot":"","sources":["../../src/web/database-manager.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA6EpE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,uCAAuC;IACvC,YAAY,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC/B;AAUD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,oBAAoB;IACpB,MAAM,EAA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