feat(logs): enhance logging functionality and UI updates

- Refactored MainLayout to always show logs in the sidebar.
- Updated i18n files for English, Russian, Simplified Chinese, and Traditional Chinese to include new log-related messages.
- Improved LogsPage styling for better layout and added runtime notices.
- Enhanced LogsPage logic to handle different server runtime kinds (CPA and Home).
- Added new API methods to handle logs fetching and request log downloading with runtime checks.
- Introduced runtime kind detection during authentication and connection status updates.
- Updated types to include server runtime kind and adjusted API responses accordingly.
This commit is contained in:
hkfires
2026-06-02 16:52:14 +08:00
parent 75da30311a
commit 8eada1cd2c
14 changed files with 501 additions and 62 deletions
+50 -9
View File
@@ -5,10 +5,11 @@
import { create } from 'zustand';
import { persist, createJSONStorage } from 'zustand/middleware';
import type { AuthState, LoginCredentials, ConnectionStatus } from '@/types';
import type { AuthState, LoginCredentials, ConnectionStatus, ServerRuntimeKind } from '@/types';
import { STORAGE_KEY_AUTH } from '@/utils/constants';
import { obfuscatedStorage } from '@/services/storage/secureStorage';
import { apiClient } from '@/services/api/client';
import { versionApi } from '@/services/api/version';
import { useConfigStore } from './useConfigStore';
import { useModelsStore } from './useModelsStore';
import { detectApiBaseFromLocation, normalizeApiBase } from '@/utils/connection';
@@ -22,12 +23,26 @@ interface AuthStoreState extends AuthState {
logout: () => void;
checkAuth: () => Promise<boolean>;
restoreSession: () => Promise<boolean>;
updateServerVersion: (version: string | null, buildDate?: string | null) => void;
updateServerVersion: (
version: string | null,
buildDate?: string | null,
runtimeKind?: ServerRuntimeKind | null
) => void;
updateServerRuntimeKind: (runtimeKind: ServerRuntimeKind) => void;
updateConnectionStatus: (status: ConnectionStatus, error?: string | null) => void;
}
let restoreSessionPromise: Promise<boolean> | null = null;
const detectRuntimeKind = async (): Promise<ServerRuntimeKind> => {
try {
return await versionApi.detectRuntimeKind();
} catch (error) {
console.warn('Runtime kind detection failed:', error);
return 'unknown';
}
};
export const useAuthStore = create<AuthStoreState>()(
persist(
(set, get) => ({
@@ -38,6 +53,7 @@ export const useAuthStore = create<AuthStoreState>()(
rememberPassword: false,
serverVersion: null,
serverBuildDate: null,
serverRuntimeKind: 'unknown',
connectionStatus: 'disconnected',
connectionError: null,
@@ -93,7 +109,12 @@ export const useAuthStore = create<AuthStoreState>()(
const rememberPassword = credentials.rememberPassword ?? get().rememberPassword ?? false;
try {
set({ connectionStatus: 'connecting' });
set({
connectionStatus: 'connecting',
serverVersion: null,
serverBuildDate: null,
serverRuntimeKind: 'unknown'
});
useModelsStore.getState().clearCache();
// 配置 API 客户端
@@ -104,6 +125,7 @@ export const useAuthStore = create<AuthStoreState>()(
// 测试连接 - 获取配置
await useConfigStore.getState().fetchConfig(undefined, true);
const runtimeKind = await detectRuntimeKind();
// 登录成功
set({
@@ -112,7 +134,8 @@ export const useAuthStore = create<AuthStoreState>()(
managementKey,
rememberPassword,
connectionStatus: 'connected',
connectionError: null
connectionError: null,
...(runtimeKind !== 'unknown' ? { serverRuntimeKind: runtimeKind } : {})
});
if (rememberPassword) {
localStorage.setItem('isLoggedIn', 'true');
@@ -145,6 +168,7 @@ export const useAuthStore = create<AuthStoreState>()(
managementKey: '',
serverVersion: null,
serverBuildDate: null,
serverRuntimeKind: 'unknown',
connectionStatus: 'disconnected',
connectionError: null
});
@@ -165,10 +189,12 @@ export const useAuthStore = create<AuthStoreState>()(
// 验证连接
await useConfigStore.getState().fetchConfig();
const runtimeKind = await detectRuntimeKind();
set({
isAuthenticated: true,
connectionStatus: 'connected'
connectionStatus: 'connected',
...(runtimeKind !== 'unknown' ? { serverRuntimeKind: runtimeKind } : {})
});
return true;
@@ -182,8 +208,16 @@ export const useAuthStore = create<AuthStoreState>()(
},
// 更新服务器版本
updateServerVersion: (version, buildDate) => {
set({ serverVersion: version || null, serverBuildDate: buildDate || null });
updateServerVersion: (version, buildDate, runtimeKind) => {
set((state) => ({
serverVersion: version || null,
serverBuildDate: buildDate || null,
serverRuntimeKind: runtimeKind || state.serverRuntimeKind
}));
},
updateServerRuntimeKind: (runtimeKind) => {
set({ serverRuntimeKind: runtimeKind });
},
// 更新连接状态
@@ -213,7 +247,8 @@ export const useAuthStore = create<AuthStoreState>()(
...(state.rememberPassword ? { managementKey: state.managementKey } : {}),
rememberPassword: state.rememberPassword,
serverVersion: state.serverVersion,
serverBuildDate: state.serverBuildDate
serverBuildDate: state.serverBuildDate,
serverRuntimeKind: state.serverRuntimeKind
})
}
)
@@ -229,7 +264,13 @@ if (typeof window !== 'undefined') {
'server-version-update',
((e: CustomEvent) => {
const detail = e.detail || {};
useAuthStore.getState().updateServerVersion(detail.version || null, detail.buildDate || null);
const runtimeKind =
detail.runtimeKind === 'cpa' || detail.runtimeKind === 'home'
? detail.runtimeKind
: null;
useAuthStore
.getState()
.updateServerVersion(detail.version || null, detail.buildDate || null, runtimeKind);
}) as EventListener
);
}