Update Astra: v2.80.19 - Refactoring Sidebar, LM Studio integration, and new tests
This commit is contained in:
+28
-1
@@ -102,7 +102,34 @@ export function _isBrainDirExplicitlySet(): boolean {
|
||||
return getBrainProfiles().length > 0;
|
||||
}
|
||||
|
||||
interface BrainFilesCacheEntry {
|
||||
files: string[];
|
||||
expiresAt: number;
|
||||
}
|
||||
const _brainFilesCache = new Map<string, BrainFilesCacheEntry>();
|
||||
const BRAIN_FILES_CACHE_TTL_MS = 5000;
|
||||
|
||||
export function findBrainFiles(dir: string): string[] {
|
||||
const now = Date.now();
|
||||
const cached = _brainFilesCache.get(dir);
|
||||
if (cached && cached.expiresAt > now) {
|
||||
return cached.files.slice();
|
||||
}
|
||||
const files = _walkBrainFiles(dir);
|
||||
_brainFilesCache.set(dir, { files, expiresAt: now + BRAIN_FILES_CACHE_TTL_MS });
|
||||
return files.slice();
|
||||
}
|
||||
|
||||
/** Force-invalidate the brain files cache (e.g. after sync or new file write). */
|
||||
export function invalidateBrainFilesCache(dir?: string): void {
|
||||
if (dir === undefined) {
|
||||
_brainFilesCache.clear();
|
||||
return;
|
||||
}
|
||||
_brainFilesCache.delete(dir);
|
||||
}
|
||||
|
||||
function _walkBrainFiles(dir: string): string[] {
|
||||
let results: string[] = [];
|
||||
if (!fs.existsSync(dir)) return results;
|
||||
const list = fs.readdirSync(dir);
|
||||
@@ -111,7 +138,7 @@ export function findBrainFiles(dir: string): string[] {
|
||||
const stat = fs.statSync(filePath);
|
||||
if (stat && stat.isDirectory()) {
|
||||
if (!EXCLUDED_DIRS.has(file)) {
|
||||
results = results.concat(findBrainFiles(filePath));
|
||||
results = results.concat(_walkBrainFiles(filePath));
|
||||
}
|
||||
} else if (file.endsWith('.md')) {
|
||||
results.push(filePath);
|
||||
|
||||
Reference in New Issue
Block a user