feat: 添加取消索引和检查索引状态的API,优化CodexLens的用户体验

This commit is contained in:
catlog22
2025-12-21 23:52:46 +08:00
parent fc4a9af0cb
commit 11d8187258
3 changed files with 154 additions and 2 deletions

View File

@@ -10,7 +10,9 @@ import {
executeCodexLens,
checkSemanticStatus,
installSemantic,
uninstallCodexLens
uninstallCodexLens,
cancelIndexing,
isIndexingInProgress
} from '../../tools/codex-lens.js';
import type { ProgressInfo } from '../../tools/codex-lens.js';
@@ -449,6 +451,31 @@ export async function handleCodexLensRoutes(ctx: RouteContext): Promise<boolean>
return true;
}
// API: Cancel CodexLens Indexing
if (pathname === '/api/codexlens/cancel' && req.method === 'POST') {
const result = cancelIndexing();
// Broadcast cancellation event
if (result.success) {
broadcastToClients({
type: 'CODEXLENS_INDEX_PROGRESS',
payload: { stage: 'cancelled', message: 'Indexing cancelled by user', percent: 0 }
});
}
res.writeHead(result.success ? 200 : 400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(result));
return true;
}
// API: Check if indexing is in progress
if (pathname === '/api/codexlens/indexing-status') {
const inProgress = isIndexingInProgress();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ success: true, inProgress }));
return true;
}
// API: CodexLens Semantic Search Status
if (pathname === '/api/codexlens/semantic/status') {
const status = await checkSemanticStatus();