Skip to content

Commit 777d5df

Browse files
author
catlog22
committed
feat: Add aggregated endpoint for CodexLens dashboard initialization and improve loading performance
1 parent c5f379b commit 777d5df

File tree

2 files changed

+110
-21
lines changed

2 files changed

+110
-21
lines changed

ccw/src/templates/dashboard-js/components/cli-status.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,54 @@ async function loadCodexLensStatus() {
129129
}
130130
}
131131

132+
/**
133+
* Load CodexLens dashboard data using aggregated endpoint (single API call)
134+
* This is optimized for the CodexLens Manager page initialization
135+
* @returns {Promise<object|null>} Dashboard init data or null on error
136+
*/
137+
async function loadCodexLensDashboardInit() {
138+
try {
139+
const response = await fetch('/api/codexlens/dashboard-init');
140+
if (!response.ok) throw new Error('Failed to load CodexLens dashboard init');
141+
const data = await response.json();
142+
143+
// Update status variables from aggregated response
144+
codexLensStatus = data.status || { ready: false };
145+
semanticStatus = data.semantic || { available: false };
146+
147+
// Expose to window for other modules
148+
if (!window.cliToolsStatus) {
149+
window.cliToolsStatus = {};
150+
}
151+
window.cliToolsStatus.codexlens = {
152+
installed: data.installed || false,
153+
version: data.status?.version || null,
154+
installedModels: [],
155+
config: data.config || {},
156+
semantic: data.semantic || {}
157+
};
158+
159+
// Store config globally for easy access
160+
window.codexLensConfig = data.config || {};
161+
window.codexLensStatusData = data.statusData || {};
162+
163+
// Update badges
164+
updateCodexLensBadge();
165+
166+
console.log('[CLI Status] CodexLens dashboard init loaded:', {
167+
installed: data.installed,
168+
version: data.status?.version,
169+
semanticAvailable: data.semantic?.available
170+
});
171+
172+
return data;
173+
} catch (err) {
174+
console.error('Failed to load CodexLens dashboard init:', err);
175+
// Fallback to individual calls
176+
return await loadCodexLensStatus();
177+
}
178+
}
179+
132180
/**
133181
* Legacy: Load semantic status individually
134182
*/

ccw/src/templates/dashboard-js/views/codexlens-manager.js

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,37 +1904,64 @@ async function renderCodexLensManager() {
19041904
container.innerHTML = '<div class="flex items-center justify-center py-12"><div class="animate-spin w-6 h-6 border-2 border-primary border-t-transparent rounded-full"></div><span class="ml-3">' + t('common.loading') + '</span></div>';
19051905

19061906
try {
1907-
// Load CodexLens status first to populate window.cliToolsStatus.codexlens
1908-
if (typeof loadCodexLensStatus === 'function') {
1907+
// Use aggregated endpoint for faster page load (single API call)
1908+
var dashboardData = null;
1909+
var config = { index_dir: '~/.codexlens/indexes', index_count: 0 };
1910+
1911+
if (typeof loadCodexLensDashboardInit === 'function') {
1912+
console.log('[CodexLens] Using aggregated dashboard-init endpoint...');
1913+
dashboardData = await loadCodexLensDashboardInit();
1914+
if (dashboardData && dashboardData.config) {
1915+
config = dashboardData.config;
1916+
console.log('[CodexLens] Dashboard init loaded, config:', config);
1917+
}
1918+
} else if (typeof loadCodexLensStatus === 'function') {
1919+
// Fallback to legacy individual calls
1920+
console.log('[CodexLens] Fallback to legacy loadCodexLensStatus...');
19091921
await loadCodexLensStatus();
1922+
var response = await fetch('/api/codexlens/config');
1923+
config = await response.json();
19101924
}
19111925

1912-
// Load LiteLLM API config for embedding backend options
1913-
try {
1914-
console.log('[CodexLens] Loading LiteLLM config...');
1915-
var litellmResponse = await fetch('/api/litellm-api/config');
1916-
console.log('[CodexLens] LiteLLM response status:', litellmResponse.status);
1917-
if (litellmResponse.ok) {
1918-
window.litellmApiConfig = await litellmResponse.json();
1919-
console.log('[CodexLens] LiteLLM config loaded:', window.litellmApiConfig);
1920-
console.log('[CodexLens] Providers:', window.litellmApiConfig?.providers?.length || 0);
1921-
} else {
1922-
console.warn('[CodexLens] LiteLLM config response not ok:', litellmResponse.status);
1926+
// Load LiteLLM API config for embedding backend options (parallel with page render)
1927+
var litellmPromise = (async () => {
1928+
try {
1929+
console.log('[CodexLens] Loading LiteLLM config...');
1930+
var litellmResponse = await fetch('/api/litellm-api/config');
1931+
if (litellmResponse.ok) {
1932+
window.litellmApiConfig = await litellmResponse.json();
1933+
console.log('[CodexLens] LiteLLM config loaded, providers:', window.litellmApiConfig?.providers?.length || 0);
1934+
}
1935+
} catch (e) {
1936+
console.warn('[CodexLens] Could not load LiteLLM config:', e);
19231937
}
1924-
} catch (e) {
1925-
console.warn('[CodexLens] Could not load LiteLLM config:', e);
1926-
}
1927-
1928-
var response = await fetch('/api/codexlens/config');
1929-
var config = await response.json();
1938+
})();
19301939

19311940
container.innerHTML = buildCodexLensManagerPage(config);
19321941
if (window.lucide) lucide.createIcons();
19331942
initCodexLensManagerPageEvents(config);
1934-
loadSemanticDepsStatus();
1943+
1944+
// Load additional data in parallel (non-blocking)
1945+
var isInstalled = window.cliToolsStatus?.codexlens?.installed || dashboardData?.installed;
1946+
1947+
// Wait for LiteLLM config before loading semantic deps (it may need provider info)
1948+
await litellmPromise;
1949+
1950+
// Load semantic deps status (skip if we already have it from dashboard-init)
1951+
if (!dashboardData?.semantic) {
1952+
loadSemanticDepsStatus();
1953+
} else {
1954+
// Use cached semantic status from dashboard-init
1955+
var semanticContainer = document.getElementById('semanticDepsStatus');
1956+
if (semanticContainer && dashboardData.semantic) {
1957+
updateSemanticDepsUI(semanticContainer, dashboardData.semantic);
1958+
}
1959+
}
1960+
19351961
loadModelList();
1962+
19361963
// Load index stats for the Index Manager section
1937-
if (window.cliToolsStatus?.codexlens?.installed) {
1964+
if (isInstalled) {
19381965
loadIndexStatsForPage();
19391966
}
19401967
} catch (err) {
@@ -1943,6 +1970,20 @@ async function renderCodexLensManager() {
19431970
}
19441971
}
19451972

1973+
/**
1974+
* Update semantic deps UI from cached data
1975+
*/
1976+
function updateSemanticDepsUI(container, semanticData) {
1977+
if (!container) return;
1978+
1979+
if (semanticData.available) {
1980+
container.innerHTML = '<div class="flex items-center gap-2 text-success"><i data-lucide="check-circle" class="w-4 h-4"></i><span>' + (semanticData.backend || 'Ready') + '</span></div>';
1981+
} else {
1982+
container.innerHTML = '<div class="flex items-center gap-2 text-muted-foreground"><i data-lucide="circle-dashed" class="w-4 h-4"></i><span>' + t('codexlens.notInstalled') + '</span></div>';
1983+
}
1984+
if (window.lucide) lucide.createIcons();
1985+
}
1986+
19461987
/**
19471988
* Build CodexLens Manager page content
19481989
*/

0 commit comments

Comments
 (0)