mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
feat: 增强 CLI 状态管理,支持从缓存加载状态并优化预加载服务
This commit is contained in:
@@ -414,7 +414,7 @@ export async function handleCodexLensSemanticRoutes(ctx: RouteContext): Promise<
|
||||
|
||||
// Special handling for litellm backend - auto-configure from litellm-api-config
|
||||
if (resolvedBackend === 'litellm' && (resolvedModelName || resolvedLiteLLMEndpoint)) {
|
||||
const selectedModel = resolvedModelName || resolvedLiteLLMEndpoint;
|
||||
const selectedModel = (resolvedModelName || resolvedLiteLLMEndpoint) as string;
|
||||
|
||||
// Find the provider that has this model
|
||||
const providers = getAllProviders(initialPath);
|
||||
|
||||
@@ -33,11 +33,43 @@ function initCliStatus() {
|
||||
* Load all statuses using aggregated endpoint (single API call)
|
||||
*/
|
||||
async function loadAllStatuses() {
|
||||
// 1. 尝试从缓存获取(预加载的数据)
|
||||
if (window.cacheManager) {
|
||||
const cached = window.cacheManager.get('all-status');
|
||||
if (cached) {
|
||||
console.log('[CLI Status] Loaded all statuses from cache');
|
||||
// 应用缓存数据
|
||||
cliToolStatus = cached.cli || {};
|
||||
codexLensStatus = cached.codexLens || { ready: false };
|
||||
semanticStatus = cached.semantic || { available: false };
|
||||
ccwInstallStatus = cached.ccwInstall || { installed: true, workflowsInstalled: true, missingFiles: [], installPath: '' };
|
||||
|
||||
// Load CLI tools config, API endpoints, and CLI Settings(这些有自己的缓存)
|
||||
await Promise.all([
|
||||
loadCliToolsConfig(),
|
||||
loadApiEndpoints(),
|
||||
loadCliSettingsEndpoints()
|
||||
]);
|
||||
|
||||
// Update badges
|
||||
updateCliBadge();
|
||||
updateCodexLensBadge();
|
||||
updateCcwInstallBadge();
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 缓存未命中,从服务器获取
|
||||
try {
|
||||
const response = await fetch('/api/status/all');
|
||||
if (!response.ok) throw new Error('Failed to load status');
|
||||
const data = await response.json();
|
||||
|
||||
// 存入缓存
|
||||
if (window.cacheManager) {
|
||||
window.cacheManager.set('all-status', data, 300000); // 5分钟
|
||||
}
|
||||
|
||||
// Update all status data - merge with config tools to ensure all tools are tracked
|
||||
cliToolStatus = data.cli || {};
|
||||
codexLensStatus = data.codexLens || { ready: false };
|
||||
|
||||
@@ -105,20 +105,29 @@ function initPreloadServices() {
|
||||
window.preloadService = new PreloadService(window.cacheManager, window.eventManager);
|
||||
|
||||
// 注册高优先级数据源(页面进入时立即预加载)
|
||||
|
||||
// 聚合状态接口 - 最高优先级(cli-status.js 的 loadAllStatuses 使用)
|
||||
window.preloadService.register('all-status',
|
||||
() => fetch('/api/status/all').then(r => r.ok ? r.json() : Promise.reject(r)),
|
||||
{ isHighPriority: true, ttl: 300000 } // 5分钟
|
||||
);
|
||||
|
||||
window.preloadService.register('dashboard-init',
|
||||
() => fetch('/api/codexlens/dashboard-init').then(r => r.ok ? r.json() : Promise.reject(r)),
|
||||
{ isHighPriority: true, ttl: 300000 } // 5分钟
|
||||
);
|
||||
|
||||
// workspace-status: NOT high priority - must wait for projectPath to be set via switchToPath()
|
||||
// Will be triggered by codexlens-manager.js when the view loads
|
||||
window.preloadService.register('workspace-status',
|
||||
() => {
|
||||
const path = encodeURIComponent(projectPath || '');
|
||||
return fetch('/api/codexlens/workspace-status?path=' + path).then(r => r.ok ? r.json() : Promise.reject(r));
|
||||
},
|
||||
{ isHighPriority: true, ttl: 120000 } // 2分钟
|
||||
{ isHighPriority: false, ttl: 120000 } // 2分钟
|
||||
);
|
||||
|
||||
// CLI 状态 - 高优先级
|
||||
// CLI 状态 - 高优先级(备用,用于独立加载)
|
||||
window.preloadService.register('cli-status',
|
||||
() => fetch('/api/cli/status').then(r => r.ok ? r.json() : Promise.reject(r)),
|
||||
{ isHighPriority: true, ttl: 300000 } // 5分钟
|
||||
|
||||
@@ -732,7 +732,7 @@ function initToolConfigModalEvents(tool, currentConfig, models) {
|
||||
function buildCliManagerSkeleton() {
|
||||
return '<div class="space-y-6">' +
|
||||
'<div class="flex items-center justify-between mb-4">' +
|
||||
'<h2 class="text-lg font-semibold">' + (t('nav.cliManager') || 'CLI Status') + '</h2>' +
|
||||
'<h2 class="text-lg font-semibold">' + (t('title.cliTools') || 'CLI Tools & CCW') + '</h2>' +
|
||||
'</div>' +
|
||||
'<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">' +
|
||||
// 左侧 Tools 区域骨架
|
||||
|
||||
Reference in New Issue
Block a user