Merge pull request #1153 from danielaskdd/show-api-version

Implemented version display in SiteHeader of webui
This commit is contained in:
Daniel.y
2025-03-22 01:55:42 +08:00
committed by GitHub
10 changed files with 119 additions and 70 deletions

View File

@@ -1 +1 @@
__api_version__ = "1.0.5"
__api_version__ = "1.2.0"

View File

@@ -23,9 +23,9 @@ from lightrag.api.utils_api import (
get_default_host,
display_splash_screen,
)
from lightrag import LightRAG
from lightrag.types import GPTKeywordExtractionFormat
from lightrag import LightRAG, __version__ as core_version
from lightrag.api import __api_version__
from lightrag.types import GPTKeywordExtractionFormat
from lightrag.utils import EmbeddingFunc
from lightrag.api.routers.document_routes import (
DocumentManager,
@@ -364,9 +364,16 @@ def create_app(args):
"token_type": "bearer",
"auth_mode": "disabled",
"message": "Authentication is disabled. Using guest access.",
"core_version": core_version,
"api_version": __api_version__,
}
return {"auth_configured": True, "auth_mode": "enabled"}
return {
"auth_configured": True,
"auth_mode": "enabled",
"core_version": core_version,
"api_version": __api_version__,
}
@app.post("/login", dependencies=[Depends(optional_api_key)])
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
@@ -383,6 +390,8 @@ def create_app(args):
"token_type": "bearer",
"auth_mode": "disabled",
"message": "Authentication is disabled. Using guest access.",
"core_version": core_version,
"api_version": __api_version__,
}
if form_data.username != username or form_data.password != password:
@@ -398,6 +407,8 @@ def create_app(args):
"access_token": user_token,
"token_type": "bearer",
"auth_mode": "enabled",
"core_version": core_version,
"api_version": __api_version__,
}
@app.get("/health", dependencies=[Depends(optional_api_key)])

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,8 +8,8 @@
<link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-BItOVH8B.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-BViPRMGA.css">
<script type="module" crossorigin src="/webui/assets/index-D8-h_xyk.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-Cq65VeVX.css">
</head>
<body>
<div id="root"></div>

View File

@@ -132,6 +132,8 @@ export type AuthStatusResponse = {
token_type?: string
auth_mode?: 'enabled' | 'disabled'
message?: string
core_version?: string
api_version?: string
}
export type LoginResponse = {
@@ -139,6 +141,8 @@ export type LoginResponse = {
token_type: string
auth_mode?: 'enabled' | 'disabled' // Authentication mode identifier
message?: string // Optional message
core_version?: string
api_version?: string
}
export const InvalidApiKeyError = 'Invalid API Key'

View File

@@ -43,7 +43,7 @@ const LoginPage = () => {
if (!status.auth_configured && status.access_token) {
// If auth is not configured, use the guest token and redirect
login(status.access_token, true)
login(status.access_token, true, status.core_version, status.api_version)
if (status.message) {
toast.info(status.message)
}
@@ -87,7 +87,7 @@ const LoginPage = () => {
// Check authentication mode
const isGuestMode = response.auth_mode === 'disabled'
login(response.access_token, isGuestMode)
login(response.access_token, isGuestMode, response.core_version, response.api_version)
if (isGuestMode) {
// Show authentication disabled notification

View File

@@ -55,7 +55,11 @@ function TabsNavigation() {
export default function SiteHeader() {
const { t } = useTranslation()
const { isGuestMode } = useAuthStore()
const { isGuestMode, coreVersion, apiVersion } = useAuthStore()
const versionDisplay = (coreVersion && apiVersion)
? `${coreVersion}/${apiVersion}`
: null;
const handleLogout = () => {
navigationService.navigateToLogin();
@@ -67,6 +71,11 @@ export default function SiteHeader() {
<ZapIcon className="size-4 text-emerald-400" aria-hidden="true" />
{/* <img src='/logo.png' className="size-4" /> */}
<span className="font-bold md:inline-block">{SiteInfo.name}</span>
{versionDisplay && (
<span className="ml-2 text-xs text-gray-500 dark:text-gray-400">
v{versionDisplay}
</span>
)}
</a>
<div className="flex h-10 flex-1 justify-center">

View File

@@ -19,7 +19,9 @@ interface BackendState {
interface AuthState {
isAuthenticated: boolean;
isGuestMode: boolean; // Add guest mode flag
login: (token: string, isGuest?: boolean) => void;
coreVersion: string | null;
apiVersion: string | null;
login: (token: string, isGuest?: boolean, coreVersion?: string | null, apiVersion?: string | null) => void;
logout: () => void;
}
@@ -84,15 +86,22 @@ const isGuestToken = (token: string): boolean => {
};
// Initialize auth state from localStorage
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean } => {
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => {
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
if (!token) {
return { isAuthenticated: false, isGuestMode: false };
return {
isAuthenticated: false,
isGuestMode: false,
coreVersion: null,
apiVersion: null
};
}
return {
isAuthenticated: true,
isGuestMode: isGuestToken(token)
isGuestMode: isGuestToken(token),
coreVersion: localStorage.getItem('LIGHTRAG-CORE-VERSION'),
apiVersion: localStorage.getItem('LIGHTRAG-API-VERSION')
};
};
@@ -103,20 +112,36 @@ export const useAuthStore = create<AuthState>(set => {
return {
isAuthenticated: initialState.isAuthenticated,
isGuestMode: initialState.isGuestMode,
coreVersion: initialState.coreVersion,
apiVersion: initialState.apiVersion,
login: (token, isGuest = false) => {
login: (token, isGuest = false, coreVersion = null, apiVersion = null) => {
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
// 存储版本信息到 localStorage
if (coreVersion) {
localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion);
}
if (apiVersion) {
localStorage.setItem('LIGHTRAG-API-VERSION', apiVersion);
}
set({
isAuthenticated: true,
isGuestMode: isGuest
isGuestMode: isGuest,
coreVersion,
apiVersion
});
},
logout: () => {
localStorage.removeItem('LIGHTRAG-API-TOKEN');
set({
isAuthenticated: false,
isGuestMode: false
isGuestMode: false,
coreVersion: null,
apiVersion: null
});
}
};