yangdx
commited on
Commit
·
073193f
1
Parent(s):
1357c9e
Implemented version display in SiteHeader of webui
Browse files- Updated API version to 1.2.0
- Stored versions in localStorage
lightrag/api/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1 |
-
__api_version__ = "1.0
|
|
|
1 |
+
__api_version__ = "1.2.0"
|
lightrag/api/lightrag_server.py
CHANGED
@@ -23,9 +23,9 @@ from lightrag.api.utils_api import (
|
|
23 |
get_default_host,
|
24 |
display_splash_screen,
|
25 |
)
|
26 |
-
from lightrag import LightRAG
|
27 |
-
from lightrag.types import GPTKeywordExtractionFormat
|
28 |
from lightrag.api import __api_version__
|
|
|
29 |
from lightrag.utils import EmbeddingFunc
|
30 |
from lightrag.api.routers.document_routes import (
|
31 |
DocumentManager,
|
@@ -364,9 +364,16 @@ def create_app(args):
|
|
364 |
"token_type": "bearer",
|
365 |
"auth_mode": "disabled",
|
366 |
"message": "Authentication is disabled. Using guest access.",
|
|
|
|
|
367 |
}
|
368 |
|
369 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
@app.post("/login", dependencies=[Depends(optional_api_key)])
|
372 |
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
|
@@ -383,6 +390,8 @@ def create_app(args):
|
|
383 |
"token_type": "bearer",
|
384 |
"auth_mode": "disabled",
|
385 |
"message": "Authentication is disabled. Using guest access.",
|
|
|
|
|
386 |
}
|
387 |
|
388 |
if form_data.username != username or form_data.password != password:
|
@@ -398,6 +407,8 @@ def create_app(args):
|
|
398 |
"access_token": user_token,
|
399 |
"token_type": "bearer",
|
400 |
"auth_mode": "enabled",
|
|
|
|
|
401 |
}
|
402 |
|
403 |
@app.get("/health", dependencies=[Depends(optional_api_key)])
|
|
|
23 |
get_default_host,
|
24 |
display_splash_screen,
|
25 |
)
|
26 |
+
from lightrag import LightRAG, __version__ as core_version
|
|
|
27 |
from lightrag.api import __api_version__
|
28 |
+
from lightrag.types import GPTKeywordExtractionFormat
|
29 |
from lightrag.utils import EmbeddingFunc
|
30 |
from lightrag.api.routers.document_routes import (
|
31 |
DocumentManager,
|
|
|
364 |
"token_type": "bearer",
|
365 |
"auth_mode": "disabled",
|
366 |
"message": "Authentication is disabled. Using guest access.",
|
367 |
+
"core_version": core_version,
|
368 |
+
"api_version": __api_version__,
|
369 |
}
|
370 |
|
371 |
+
return {
|
372 |
+
"auth_configured": True,
|
373 |
+
"auth_mode": "enabled",
|
374 |
+
"core_version": core_version,
|
375 |
+
"api_version": __api_version__,
|
376 |
+
}
|
377 |
|
378 |
@app.post("/login", dependencies=[Depends(optional_api_key)])
|
379 |
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
|
|
|
390 |
"token_type": "bearer",
|
391 |
"auth_mode": "disabled",
|
392 |
"message": "Authentication is disabled. Using guest access.",
|
393 |
+
"core_version": core_version,
|
394 |
+
"api_version": __api_version__,
|
395 |
}
|
396 |
|
397 |
if form_data.username != username or form_data.password != password:
|
|
|
407 |
"access_token": user_token,
|
408 |
"token_type": "bearer",
|
409 |
"auth_mode": "enabled",
|
410 |
+
"core_version": core_version,
|
411 |
+
"api_version": __api_version__,
|
412 |
}
|
413 |
|
414 |
@app.get("/health", dependencies=[Depends(optional_api_key)])
|
lightrag_webui/src/api/lightrag.ts
CHANGED
@@ -132,6 +132,8 @@ export type AuthStatusResponse = {
|
|
132 |
token_type?: string
|
133 |
auth_mode?: 'enabled' | 'disabled'
|
134 |
message?: string
|
|
|
|
|
135 |
}
|
136 |
|
137 |
export type LoginResponse = {
|
@@ -139,6 +141,8 @@ export type LoginResponse = {
|
|
139 |
token_type: string
|
140 |
auth_mode?: 'enabled' | 'disabled' // Authentication mode identifier
|
141 |
message?: string // Optional message
|
|
|
|
|
142 |
}
|
143 |
|
144 |
export const InvalidApiKeyError = 'Invalid API Key'
|
|
|
132 |
token_type?: string
|
133 |
auth_mode?: 'enabled' | 'disabled'
|
134 |
message?: string
|
135 |
+
core_version?: string
|
136 |
+
api_version?: string
|
137 |
}
|
138 |
|
139 |
export type LoginResponse = {
|
|
|
141 |
token_type: string
|
142 |
auth_mode?: 'enabled' | 'disabled' // Authentication mode identifier
|
143 |
message?: string // Optional message
|
144 |
+
core_version?: string
|
145 |
+
api_version?: string
|
146 |
}
|
147 |
|
148 |
export const InvalidApiKeyError = 'Invalid API Key'
|
lightrag_webui/src/features/LoginPage.tsx
CHANGED
@@ -43,7 +43,7 @@ const LoginPage = () => {
|
|
43 |
|
44 |
if (!status.auth_configured && status.access_token) {
|
45 |
// If auth is not configured, use the guest token and redirect
|
46 |
-
login(status.access_token, true)
|
47 |
if (status.message) {
|
48 |
toast.info(status.message)
|
49 |
}
|
@@ -87,7 +87,7 @@ const LoginPage = () => {
|
|
87 |
|
88 |
// Check authentication mode
|
89 |
const isGuestMode = response.auth_mode === 'disabled'
|
90 |
-
login(response.access_token, isGuestMode)
|
91 |
|
92 |
if (isGuestMode) {
|
93 |
// Show authentication disabled notification
|
|
|
43 |
|
44 |
if (!status.auth_configured && status.access_token) {
|
45 |
// If auth is not configured, use the guest token and redirect
|
46 |
+
login(status.access_token, true, status.core_version, status.api_version)
|
47 |
if (status.message) {
|
48 |
toast.info(status.message)
|
49 |
}
|
|
|
87 |
|
88 |
// Check authentication mode
|
89 |
const isGuestMode = response.auth_mode === 'disabled'
|
90 |
+
login(response.access_token, isGuestMode, response.core_version, response.api_version)
|
91 |
|
92 |
if (isGuestMode) {
|
93 |
// Show authentication disabled notification
|
lightrag_webui/src/features/SiteHeader.tsx
CHANGED
@@ -55,7 +55,11 @@ function TabsNavigation() {
|
|
55 |
|
56 |
export default function SiteHeader() {
|
57 |
const { t } = useTranslation()
|
58 |
-
const { isGuestMode } = useAuthStore()
|
|
|
|
|
|
|
|
|
59 |
|
60 |
const handleLogout = () => {
|
61 |
navigationService.navigateToLogin();
|
@@ -67,6 +71,11 @@ export default function SiteHeader() {
|
|
67 |
<ZapIcon className="size-4 text-emerald-400" aria-hidden="true" />
|
68 |
{/* <img src='/logo.png' className="size-4" /> */}
|
69 |
<span className="font-bold md:inline-block">{SiteInfo.name}</span>
|
|
|
|
|
|
|
|
|
|
|
70 |
</a>
|
71 |
|
72 |
<div className="flex h-10 flex-1 justify-center">
|
|
|
55 |
|
56 |
export default function SiteHeader() {
|
57 |
const { t } = useTranslation()
|
58 |
+
const { isGuestMode, coreVersion, apiVersion } = useAuthStore()
|
59 |
+
|
60 |
+
const versionDisplay = (coreVersion && apiVersion)
|
61 |
+
? `${coreVersion}/${apiVersion}`
|
62 |
+
: null;
|
63 |
|
64 |
const handleLogout = () => {
|
65 |
navigationService.navigateToLogin();
|
|
|
71 |
<ZapIcon className="size-4 text-emerald-400" aria-hidden="true" />
|
72 |
{/* <img src='/logo.png' className="size-4" /> */}
|
73 |
<span className="font-bold md:inline-block">{SiteInfo.name}</span>
|
74 |
+
{versionDisplay && (
|
75 |
+
<span className="ml-2 text-xs text-gray-500 dark:text-gray-400">
|
76 |
+
v{versionDisplay}
|
77 |
+
</span>
|
78 |
+
)}
|
79 |
</a>
|
80 |
|
81 |
<div className="flex h-10 flex-1 justify-center">
|
lightrag_webui/src/stores/state.ts
CHANGED
@@ -19,7 +19,9 @@ interface BackendState {
|
|
19 |
interface AuthState {
|
20 |
isAuthenticated: boolean;
|
21 |
isGuestMode: boolean; // Add guest mode flag
|
22 |
-
|
|
|
|
|
23 |
logout: () => void;
|
24 |
}
|
25 |
|
@@ -84,15 +86,22 @@ const isGuestToken = (token: string): boolean => {
|
|
84 |
};
|
85 |
|
86 |
// Initialize auth state from localStorage
|
87 |
-
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean } => {
|
88 |
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
|
89 |
if (!token) {
|
90 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|
92 |
|
93 |
return {
|
94 |
isAuthenticated: true,
|
95 |
-
isGuestMode: isGuestToken(token)
|
|
|
|
|
96 |
};
|
97 |
};
|
98 |
|
@@ -103,20 +112,36 @@ export const useAuthStore = create<AuthState>(set => {
|
|
103 |
return {
|
104 |
isAuthenticated: initialState.isAuthenticated,
|
105 |
isGuestMode: initialState.isGuestMode,
|
|
|
|
|
106 |
|
107 |
-
login: (token, isGuest = false) => {
|
108 |
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
set({
|
110 |
isAuthenticated: true,
|
111 |
-
isGuestMode: isGuest
|
|
|
|
|
112 |
});
|
113 |
},
|
114 |
|
115 |
logout: () => {
|
116 |
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
|
|
117 |
set({
|
118 |
isAuthenticated: false,
|
119 |
-
isGuestMode: false
|
|
|
|
|
120 |
});
|
121 |
}
|
122 |
};
|
|
|
19 |
interface AuthState {
|
20 |
isAuthenticated: boolean;
|
21 |
isGuestMode: boolean; // Add guest mode flag
|
22 |
+
coreVersion: string | null;
|
23 |
+
apiVersion: string | null;
|
24 |
+
login: (token: string, isGuest?: boolean, coreVersion?: string | null, apiVersion?: string | null) => void;
|
25 |
logout: () => void;
|
26 |
}
|
27 |
|
|
|
86 |
};
|
87 |
|
88 |
// Initialize auth state from localStorage
|
89 |
+
const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => {
|
90 |
const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
|
91 |
if (!token) {
|
92 |
+
return {
|
93 |
+
isAuthenticated: false,
|
94 |
+
isGuestMode: false,
|
95 |
+
coreVersion: null,
|
96 |
+
apiVersion: null
|
97 |
+
};
|
98 |
}
|
99 |
|
100 |
return {
|
101 |
isAuthenticated: true,
|
102 |
+
isGuestMode: isGuestToken(token),
|
103 |
+
coreVersion: localStorage.getItem('LIGHTRAG-CORE-VERSION'),
|
104 |
+
apiVersion: localStorage.getItem('LIGHTRAG-API-VERSION')
|
105 |
};
|
106 |
};
|
107 |
|
|
|
112 |
return {
|
113 |
isAuthenticated: initialState.isAuthenticated,
|
114 |
isGuestMode: initialState.isGuestMode,
|
115 |
+
coreVersion: initialState.coreVersion,
|
116 |
+
apiVersion: initialState.apiVersion,
|
117 |
|
118 |
+
login: (token, isGuest = false, coreVersion = null, apiVersion = null) => {
|
119 |
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
|
120 |
+
|
121 |
+
// 存储版本信息到 localStorage
|
122 |
+
if (coreVersion) {
|
123 |
+
localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion);
|
124 |
+
}
|
125 |
+
if (apiVersion) {
|
126 |
+
localStorage.setItem('LIGHTRAG-API-VERSION', apiVersion);
|
127 |
+
}
|
128 |
+
|
129 |
set({
|
130 |
isAuthenticated: true,
|
131 |
+
isGuestMode: isGuest,
|
132 |
+
coreVersion,
|
133 |
+
apiVersion
|
134 |
});
|
135 |
},
|
136 |
|
137 |
logout: () => {
|
138 |
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
139 |
+
|
140 |
set({
|
141 |
isAuthenticated: false,
|
142 |
+
isGuestMode: false,
|
143 |
+
coreVersion: null,
|
144 |
+
apiVersion: null
|
145 |
});
|
146 |
}
|
147 |
};
|