@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,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// DatabaseManager - Manages RAG database lifecycle and configuration
|
|
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.DatabaseManager = void 0;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const promises_1 = require("node:fs/promises");
|
|
10
|
+
const node_os_1 = require("node:os");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const schemas_js_1 = require("../server/schemas.js");
|
|
13
|
+
// ============================================
|
|
14
|
+
// Constants
|
|
15
|
+
// ============================================
|
|
16
|
+
/** Config directory for rag-vault */
|
|
17
|
+
const CONFIG_DIR = node_path_1.default.join((0, node_os_1.homedir)(), '.rag-vault');
|
|
18
|
+
/** Recent databases file path */
|
|
19
|
+
const RECENT_DBS_FILE = node_path_1.default.join(CONFIG_DIR, 'recent-dbs.json');
|
|
20
|
+
/** LanceDB directory name (indicator of a valid database) */
|
|
21
|
+
const LANCEDB_DIR_NAME = 'chunks.lance';
|
|
22
|
+
/** Maximum number of recent databases to track */
|
|
23
|
+
const MAX_RECENT_DATABASES = 10;
|
|
24
|
+
/**
|
|
25
|
+
* Get allowed scan roots from environment variable or default to home directory
|
|
26
|
+
* ALLOWED_SCAN_ROOTS: comma-separated list of absolute paths
|
|
27
|
+
*/
|
|
28
|
+
function getAllowedScanRoots() {
|
|
29
|
+
const envRoots = process.env['ALLOWED_SCAN_ROOTS'];
|
|
30
|
+
if (envRoots) {
|
|
31
|
+
return envRoots.split(',').map((p) => node_path_1.default.resolve(p.trim()));
|
|
32
|
+
}
|
|
33
|
+
// Default: only allow scanning within home directory
|
|
34
|
+
return [(0, node_os_1.homedir)()];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate that a path is within allowed scan roots (prevents path traversal)
|
|
38
|
+
* @param targetPath - Path to validate (will be resolved and normalized)
|
|
39
|
+
* @returns true if path is within allowed roots
|
|
40
|
+
*/
|
|
41
|
+
function isPathWithinAllowedRoots(targetPath) {
|
|
42
|
+
const allowedRoots = getAllowedScanRoots();
|
|
43
|
+
let resolvedPath;
|
|
44
|
+
try {
|
|
45
|
+
// Resolve to absolute path and resolve symlinks
|
|
46
|
+
resolvedPath = (0, node_fs_1.existsSync)(targetPath) ? (0, node_fs_1.realpathSync)(targetPath) : node_path_1.default.resolve(targetPath);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// If we can't resolve the path, reject it
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
// Check if the resolved path is within any allowed root
|
|
53
|
+
return allowedRoots.some((root) => {
|
|
54
|
+
const normalizedRoot = node_path_1.default.normalize(root);
|
|
55
|
+
const normalizedTarget = node_path_1.default.normalize(resolvedPath);
|
|
56
|
+
// Ensure exact prefix match (avoid /home/user matching /home/username)
|
|
57
|
+
return (normalizedTarget === normalizedRoot || normalizedTarget.startsWith(normalizedRoot + node_path_1.default.sep));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Expand tilde (~) in path to home directory
|
|
62
|
+
*/
|
|
63
|
+
function expandTilde(filePath) {
|
|
64
|
+
if (filePath.startsWith('~/')) {
|
|
65
|
+
return node_path_1.default.join((0, node_os_1.homedir)(), filePath.slice(2));
|
|
66
|
+
}
|
|
67
|
+
if (filePath === '~') {
|
|
68
|
+
return (0, node_os_1.homedir)();
|
|
69
|
+
}
|
|
70
|
+
return filePath;
|
|
71
|
+
}
|
|
72
|
+
// ============================================
|
|
73
|
+
// DatabaseManager Class
|
|
74
|
+
// ============================================
|
|
75
|
+
/**
|
|
76
|
+
* DatabaseManager handles RAG database lifecycle management
|
|
77
|
+
*
|
|
78
|
+
* Responsibilities:
|
|
79
|
+
* - Track current database connection
|
|
80
|
+
* - Hot-swap between databases
|
|
81
|
+
* - Persist recent databases list
|
|
82
|
+
* - Discover databases by scanning directories
|
|
83
|
+
*/
|
|
84
|
+
class DatabaseManager {
|
|
85
|
+
constructor(serverFactory, baseConfig) {
|
|
86
|
+
this.currentServer = null;
|
|
87
|
+
this.currentConfig = null;
|
|
88
|
+
this.switchPromise = null;
|
|
89
|
+
this.serverFactory = serverFactory;
|
|
90
|
+
this.baseConfig = baseConfig;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Initialize with a database path
|
|
94
|
+
*/
|
|
95
|
+
async initialize(dbPath) {
|
|
96
|
+
await this.ensureConfigDir();
|
|
97
|
+
const config = {
|
|
98
|
+
...this.baseConfig,
|
|
99
|
+
dbPath,
|
|
100
|
+
};
|
|
101
|
+
this.currentServer = this.serverFactory(config);
|
|
102
|
+
this.currentConfig = config;
|
|
103
|
+
await this.currentServer.initialize();
|
|
104
|
+
// Add to recent databases
|
|
105
|
+
await this.addToRecent(dbPath, this.baseConfig.modelName);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get current RAG server instance
|
|
109
|
+
*/
|
|
110
|
+
getServer() {
|
|
111
|
+
if (!this.currentServer) {
|
|
112
|
+
throw new Error('DatabaseManager not initialized. Call initialize() first.');
|
|
113
|
+
}
|
|
114
|
+
return this.currentServer;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get current database configuration with stats
|
|
118
|
+
*/
|
|
119
|
+
async getCurrentConfig() {
|
|
120
|
+
if (!this.currentServer || !this.currentConfig) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const serverConfig = this.currentServer.getConfig();
|
|
124
|
+
const statusResult = await this.currentServer.handleStatus();
|
|
125
|
+
// Safely extract text from response
|
|
126
|
+
// The return type is { content: [{ type: 'text'; text: string }] }
|
|
127
|
+
const firstContent = statusResult.content[0];
|
|
128
|
+
if (typeof firstContent.text !== 'string') {
|
|
129
|
+
throw new Error('Malformed server response: missing text in content');
|
|
130
|
+
}
|
|
131
|
+
// Parse and validate status response with Zod
|
|
132
|
+
const parsed = schemas_js_1.StatusResponseSchema.safeParse(JSON.parse(firstContent.text));
|
|
133
|
+
if (!parsed.success) {
|
|
134
|
+
throw new Error(`Invalid status response: ${parsed.error.message}`);
|
|
135
|
+
}
|
|
136
|
+
const status = parsed.data;
|
|
137
|
+
return {
|
|
138
|
+
dbPath: serverConfig.dbPath,
|
|
139
|
+
modelName: serverConfig.modelName,
|
|
140
|
+
name: this.getNameFromPath(serverConfig.dbPath),
|
|
141
|
+
documentCount: status.documentCount,
|
|
142
|
+
chunkCount: status.chunkCount,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Switch to a different database
|
|
147
|
+
*
|
|
148
|
+
* Uses promise-based mutex to prevent race conditions from concurrent switch attempts.
|
|
149
|
+
*/
|
|
150
|
+
async switchDatabase(newDbPath) {
|
|
151
|
+
// Prevent concurrent switches using promise-based mutex
|
|
152
|
+
if (this.switchPromise) {
|
|
153
|
+
throw new Error('Database switch already in progress');
|
|
154
|
+
}
|
|
155
|
+
// Expand tilde to home directory
|
|
156
|
+
const resolvedPath = expandTilde(newDbPath);
|
|
157
|
+
// Validate the new path exists and is a valid database
|
|
158
|
+
if (!(0, node_fs_1.existsSync)(resolvedPath)) {
|
|
159
|
+
throw new Error(`Database path does not exist: ${resolvedPath}`);
|
|
160
|
+
}
|
|
161
|
+
const lanceDbPath = node_path_1.default.join(resolvedPath, LANCEDB_DIR_NAME);
|
|
162
|
+
if (!(0, node_fs_1.existsSync)(lanceDbPath)) {
|
|
163
|
+
throw new Error(`Invalid database: ${resolvedPath} (missing LanceDB data)`);
|
|
164
|
+
}
|
|
165
|
+
// Set promise atomically before any async operations
|
|
166
|
+
this.switchPromise = this.performSwitch(resolvedPath).finally(() => {
|
|
167
|
+
this.switchPromise = null;
|
|
168
|
+
});
|
|
169
|
+
return this.switchPromise;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Internal method to perform the actual database switch
|
|
173
|
+
*/
|
|
174
|
+
async performSwitch(resolvedPath) {
|
|
175
|
+
// Close current server
|
|
176
|
+
if (this.currentServer) {
|
|
177
|
+
await this.currentServer.close();
|
|
178
|
+
}
|
|
179
|
+
// Create new server with new path
|
|
180
|
+
const config = {
|
|
181
|
+
...this.baseConfig,
|
|
182
|
+
dbPath: resolvedPath,
|
|
183
|
+
};
|
|
184
|
+
this.currentServer = this.serverFactory(config);
|
|
185
|
+
this.currentConfig = config;
|
|
186
|
+
await this.currentServer.initialize();
|
|
187
|
+
// Update recent databases
|
|
188
|
+
await this.addToRecent(resolvedPath, this.baseConfig.modelName);
|
|
189
|
+
console.log(`Switched to database: ${resolvedPath}`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a new database
|
|
193
|
+
*/
|
|
194
|
+
async createDatabase(options) {
|
|
195
|
+
// Expand tilde to home directory
|
|
196
|
+
const resolvedPath = expandTilde(options.dbPath);
|
|
197
|
+
// Check if path already exists
|
|
198
|
+
if ((0, node_fs_1.existsSync)(resolvedPath)) {
|
|
199
|
+
const lanceDbPath = node_path_1.default.join(resolvedPath, LANCEDB_DIR_NAME);
|
|
200
|
+
if ((0, node_fs_1.existsSync)(lanceDbPath)) {
|
|
201
|
+
throw new Error(`Database already exists at: ${resolvedPath}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Create the directory if needed
|
|
205
|
+
await (0, promises_1.mkdir)(resolvedPath, { recursive: true });
|
|
206
|
+
// Switch to the new database (it will be empty initially)
|
|
207
|
+
// The VectorStore will create the table on first data insertion
|
|
208
|
+
await this.switchToNewDatabase(resolvedPath);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Switch to a new (possibly empty) database
|
|
212
|
+
*
|
|
213
|
+
* Uses promise-based mutex to prevent race conditions from concurrent switch attempts.
|
|
214
|
+
*/
|
|
215
|
+
async switchToNewDatabase(newDbPath) {
|
|
216
|
+
if (this.switchPromise) {
|
|
217
|
+
throw new Error('Database switch already in progress');
|
|
218
|
+
}
|
|
219
|
+
// Set promise atomically before any async operations
|
|
220
|
+
this.switchPromise = this.performSwitchToNew(newDbPath).finally(() => {
|
|
221
|
+
this.switchPromise = null;
|
|
222
|
+
});
|
|
223
|
+
return this.switchPromise;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Internal method to perform the actual switch to a new database
|
|
227
|
+
*/
|
|
228
|
+
async performSwitchToNew(newDbPath) {
|
|
229
|
+
if (this.currentServer) {
|
|
230
|
+
await this.currentServer.close();
|
|
231
|
+
}
|
|
232
|
+
const config = {
|
|
233
|
+
...this.baseConfig,
|
|
234
|
+
dbPath: newDbPath,
|
|
235
|
+
};
|
|
236
|
+
this.currentServer = this.serverFactory(config);
|
|
237
|
+
this.currentConfig = config;
|
|
238
|
+
await this.currentServer.initialize();
|
|
239
|
+
await this.addToRecent(newDbPath, this.baseConfig.modelName);
|
|
240
|
+
console.log(`Created and switched to database: ${newDbPath}`);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get list of recent databases
|
|
244
|
+
*
|
|
245
|
+
* Handles errors appropriately:
|
|
246
|
+
* - File not found: Normal case, returns empty array
|
|
247
|
+
* - Parse/validation error: Logs error but returns empty array to allow recovery
|
|
248
|
+
*/
|
|
249
|
+
async getRecentDatabases() {
|
|
250
|
+
await this.ensureConfigDir();
|
|
251
|
+
if (!(0, node_fs_1.existsSync)(RECENT_DBS_FILE)) {
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const content = await (0, promises_1.readFile)(RECENT_DBS_FILE, 'utf-8');
|
|
256
|
+
const jsonData = JSON.parse(content);
|
|
257
|
+
// Validate with Zod schema
|
|
258
|
+
const parsed = schemas_js_1.RecentDatabasesFileSchema.safeParse(jsonData);
|
|
259
|
+
if (!parsed.success) {
|
|
260
|
+
console.error('Recent databases file has invalid format:', parsed.error.message);
|
|
261
|
+
console.error('File will be overwritten on next database access.');
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
// Filter out databases that no longer exist
|
|
265
|
+
const validDatabases = parsed.data.databases.filter((db) => (0, node_fs_1.existsSync)(db.path));
|
|
266
|
+
return validDatabases;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
// Differentiate between file-not-found and other errors
|
|
270
|
+
const nodeError = error;
|
|
271
|
+
if (nodeError.code === 'ENOENT') {
|
|
272
|
+
// File was deleted between check and read - OK
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
// JSON parse error or other issues - log but allow recovery
|
|
276
|
+
console.error('Failed to read recent databases (file may be corrupted):', error);
|
|
277
|
+
console.error('File will be overwritten on next database access.');
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Scan a directory for LanceDB databases
|
|
283
|
+
*
|
|
284
|
+
* Security: Only scans within allowed roots (ALLOWED_SCAN_ROOTS env var or home directory)
|
|
285
|
+
* to prevent path traversal attacks.
|
|
286
|
+
*/
|
|
287
|
+
async scanForDatabases(scanPath) {
|
|
288
|
+
// Expand tilde to home directory
|
|
289
|
+
const resolvedPath = expandTilde(scanPath);
|
|
290
|
+
// Security: Validate path is within allowed roots
|
|
291
|
+
if (!isPathWithinAllowedRoots(resolvedPath)) {
|
|
292
|
+
const allowedRoots = getAllowedScanRoots();
|
|
293
|
+
throw new Error(`Scan path "${resolvedPath}" is outside allowed roots. ` +
|
|
294
|
+
`Allowed: ${allowedRoots.join(', ')}. ` +
|
|
295
|
+
`Set ALLOWED_SCAN_ROOTS environment variable to allow additional paths.`);
|
|
296
|
+
}
|
|
297
|
+
const results = [];
|
|
298
|
+
const recentDbs = await this.getRecentDatabases();
|
|
299
|
+
const knownPaths = new Set(recentDbs.map((db) => db.path));
|
|
300
|
+
if (!(0, node_fs_1.existsSync)(resolvedPath)) {
|
|
301
|
+
throw new Error(`Scan path does not exist: ${resolvedPath}`);
|
|
302
|
+
}
|
|
303
|
+
const scanStat = await (0, promises_1.stat)(resolvedPath);
|
|
304
|
+
if (!scanStat.isDirectory()) {
|
|
305
|
+
throw new Error(`Scan path is not a directory: ${resolvedPath}`);
|
|
306
|
+
}
|
|
307
|
+
// Check if resolvedPath itself is a database
|
|
308
|
+
const lanceDbPath = node_path_1.default.join(resolvedPath, LANCEDB_DIR_NAME);
|
|
309
|
+
if ((0, node_fs_1.existsSync)(lanceDbPath)) {
|
|
310
|
+
results.push({
|
|
311
|
+
path: resolvedPath,
|
|
312
|
+
name: this.getNameFromPath(resolvedPath),
|
|
313
|
+
isKnown: knownPaths.has(resolvedPath),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
// Scan subdirectories (one level deep)
|
|
317
|
+
try {
|
|
318
|
+
const entries = await (0, promises_1.readdir)(resolvedPath, { withFileTypes: true });
|
|
319
|
+
for (const entry of entries) {
|
|
320
|
+
if (!entry.isDirectory())
|
|
321
|
+
continue;
|
|
322
|
+
const subPath = node_path_1.default.join(resolvedPath, entry.name);
|
|
323
|
+
const subLanceDbPath = node_path_1.default.join(subPath, LANCEDB_DIR_NAME);
|
|
324
|
+
if ((0, node_fs_1.existsSync)(subLanceDbPath)) {
|
|
325
|
+
results.push({
|
|
326
|
+
path: subPath,
|
|
327
|
+
name: this.getNameFromPath(subPath),
|
|
328
|
+
isKnown: knownPaths.has(subPath),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
console.error(`Failed to scan directory ${resolvedPath}:`, error);
|
|
335
|
+
}
|
|
336
|
+
return results;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Add a database to recent list
|
|
340
|
+
*/
|
|
341
|
+
async addToRecent(dbPath, modelName) {
|
|
342
|
+
const databases = await this.getRecentDatabases();
|
|
343
|
+
// Remove existing entry for this path
|
|
344
|
+
const filtered = databases.filter((db) => db.path !== dbPath);
|
|
345
|
+
// Add new entry at the beginning
|
|
346
|
+
const newEntry = {
|
|
347
|
+
path: dbPath,
|
|
348
|
+
name: this.getNameFromPath(dbPath),
|
|
349
|
+
lastAccessed: new Date().toISOString(),
|
|
350
|
+
modelName,
|
|
351
|
+
};
|
|
352
|
+
const updated = [newEntry, ...filtered].slice(0, MAX_RECENT_DATABASES);
|
|
353
|
+
const fileContent = {
|
|
354
|
+
version: 1,
|
|
355
|
+
databases: updated,
|
|
356
|
+
};
|
|
357
|
+
await (0, promises_1.writeFile)(RECENT_DBS_FILE, JSON.stringify(fileContent, null, 2), 'utf-8');
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Derive a human-readable name from a path
|
|
361
|
+
*/
|
|
362
|
+
getNameFromPath(dbPath) {
|
|
363
|
+
// Get the last directory name
|
|
364
|
+
const basename = node_path_1.default.basename(dbPath);
|
|
365
|
+
// If it's a generic name, include parent directory
|
|
366
|
+
if (basename === 'db' || basename === 'data' || basename === 'rag') {
|
|
367
|
+
const parent = node_path_1.default.basename(node_path_1.default.dirname(dbPath));
|
|
368
|
+
return `${parent}/${basename}`;
|
|
369
|
+
}
|
|
370
|
+
return basename;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Ensure config directory exists
|
|
374
|
+
*/
|
|
375
|
+
async ensureConfigDir() {
|
|
376
|
+
if (!(0, node_fs_1.existsSync)(CONFIG_DIR)) {
|
|
377
|
+
await (0, promises_1.mkdir)(CONFIG_DIR, { recursive: true });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
exports.DatabaseManager = DatabaseManager;
|
|
382
|
+
//# sourceMappingURL=database-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-manager.js","sourceRoot":"","sources":["../../src/web/database-manager.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,qCAAkD;AAClD,+CAA4E;AAC5E,qC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E,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;IACjF,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,MAAc;QACpC,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEtC,mDAAmD;QACnD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YACnE,MAAM,MAAM,GAAG,mBAAI,CAAC,QAAQ,CAAC,mBAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;YAClD,OAAO,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAA;QAChC,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,eAAe;QAC3B,IAAI,CAAC,IAAA,oBAAU,EAAC,UAAU,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAA,gBAAK,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC9C,CAAC;IACH,CAAC;CACF;AA1WD,0CA0WC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Express } from 'express';
|
|
2
|
+
import type { RAGServer } from '../server/index.js';
|
|
3
|
+
import type { DatabaseManager } from './database-manager.js';
|
|
4
|
+
export type { ServerAccessor } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* HTTP server configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpServerConfig {
|
|
9
|
+
/** Port to listen on */
|
|
10
|
+
port: number;
|
|
11
|
+
/** Upload directory for temporary files */
|
|
12
|
+
uploadDir: string;
|
|
13
|
+
/** Static files directory (for production builds) */
|
|
14
|
+
staticDir?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create and configure Express app with DatabaseManager
|
|
18
|
+
*/
|
|
19
|
+
export declare function createHttpServerWithManager(dbManager: DatabaseManager, config: HttpServerConfig): Promise<Express>;
|
|
20
|
+
/**
|
|
21
|
+
* Create and configure Express app (legacy - direct RAGServer)
|
|
22
|
+
*/
|
|
23
|
+
export declare function createHttpServer(ragServer: RAGServer, config: HttpServerConfig): Promise<Express>;
|
|
24
|
+
/**
|
|
25
|
+
* Start HTTP server
|
|
26
|
+
*/
|
|
27
|
+
export declare function startServer(app: Express, port: number): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=http-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/web/http-server.ts"],"names":[],"mappings":"AAQA,OAAgB,EAAE,KAAK,OAAO,EAAkD,MAAM,SAAS,CAAA;AAI/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAiE5D,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,OAAO,CAAC,CAElB;AAkOD;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOrE"}
|