mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-12 13:50:59 +00:00
perf: detailed control of models service displaying
This commit is contained in:
@@ -17,7 +17,7 @@ import { Switch } from '@/components/ui/switch';
|
|||||||
import { ControllerRenderProps } from 'react-hook-form';
|
import { ControllerRenderProps } from 'react-hook-form';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { httpClient, systemInfo } from '@/app/infra/http/HttpClient';
|
import { httpClient, systemInfo, userInfo } from '@/app/infra/http';
|
||||||
import {
|
import {
|
||||||
LLMModel,
|
LLMModel,
|
||||||
Bot,
|
Bot,
|
||||||
@@ -99,8 +99,11 @@ export default function DynamicFormItemComponent({
|
|||||||
.getProviderLLMModels()
|
.getProviderLLMModels()
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
let models = resp.models;
|
let models = resp.models;
|
||||||
// Filter out space-chat-completions models when models service is disabled
|
// Filter out space-chat-completions models when not logged in with space account or when models service is disabled
|
||||||
if (systemInfo.disable_models_service) {
|
if (
|
||||||
|
systemInfo.disable_models_service ||
|
||||||
|
userInfo?.account_type !== 'space'
|
||||||
|
) {
|
||||||
models = models.filter(
|
models = models.filter(
|
||||||
(m) => m.provider?.requester !== 'space-chat-completions',
|
(m) => m.provider?.requester !== 'space-chat-completions',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { LLMModel, EmbeddingModel } from '@/app/infra/entities/api';
|
import { LLMModel, EmbeddingModel } from '@/app/infra/entities/api';
|
||||||
import { ExtraArg, ModelType, TestResult } from '../types';
|
import { ExtraArg, ModelType, TestResult } from '../types';
|
||||||
import ExtraArgsEditor from './ExtraArgsEditor';
|
import ExtraArgsEditor from './ExtraArgsEditor';
|
||||||
|
import { userInfo } from '@/app/infra/http';
|
||||||
|
|
||||||
interface ModelItemProps {
|
interface ModelItemProps {
|
||||||
model: LLMModel | EmbeddingModel;
|
model: LLMModel | EmbeddingModel;
|
||||||
@@ -113,10 +114,15 @@ export default function ModelItem({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check if popover should be disabled (space models when not logged in)
|
||||||
|
const isPopoverDisabled =
|
||||||
|
isLangBotModels && userInfo?.account_type !== 'space';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
open={isEditOpen}
|
open={isEditOpen && !isPopoverDisabled}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
|
if (isPopoverDisabled) return;
|
||||||
if (open) {
|
if (open) {
|
||||||
onOpenEditModel(model.uuid);
|
onOpenEditModel(model.uuid);
|
||||||
} else {
|
} else {
|
||||||
@@ -125,7 +131,13 @@ export default function ModelItem({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<div className="flex items-center justify-between py-2 px-3 rounded-md border bg-background hover:bg-accent cursor-pointer">
|
<div
|
||||||
|
className={`flex items-center justify-between py-2 px-3 rounded-md border bg-background ${
|
||||||
|
isPopoverDisabled
|
||||||
|
? 'cursor-not-allowed opacity-60'
|
||||||
|
: 'hover:bg-accent cursor-pointer'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<span className="text-sm font-medium">{model.name}</span>
|
<span className="text-sm font-medium">{model.name}</span>
|
||||||
<Badge variant="secondary" className="text-xs">
|
<Badge variant="secondary" className="text-xs">
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
FormDescription,
|
FormDescription,
|
||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { httpClient, systemInfo } from '@/app/infra/http/HttpClient';
|
import { httpClient, systemInfo, userInfo } from '@/app/infra/http';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -101,8 +101,11 @@ export default function KBForm({
|
|||||||
const getEmbeddingModelNameList = async () => {
|
const getEmbeddingModelNameList = async () => {
|
||||||
const resp = await httpClient.getProviderEmbeddingModels();
|
const resp = await httpClient.getProviderEmbeddingModels();
|
||||||
let models = resp.models;
|
let models = resp.models;
|
||||||
// Filter out space-chat-completions models when models service is disabled
|
// Filter out space-chat-completions models when not logged in with space account or when models service is disabled
|
||||||
if (systemInfo.disable_models_service) {
|
if (
|
||||||
|
systemInfo.disable_models_service ||
|
||||||
|
userInfo?.account_type !== 'space'
|
||||||
|
) {
|
||||||
models = models.filter(
|
models = models.filter(
|
||||||
(m) => m.provider?.requester !== 'space-chat-completions',
|
(m) => m.provider?.requester !== 'space-chat-completions',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
import styles from './layout.module.css';
|
import styles from './layout.module.css';
|
||||||
import HomeSidebar from '@/app/home/components/home-sidebar/HomeSidebar';
|
import HomeSidebar from '@/app/home/components/home-sidebar/HomeSidebar';
|
||||||
import HomeTitleBar from '@/app/home/components/home-titlebar/HomeTitleBar';
|
import HomeTitleBar from '@/app/home/components/home-titlebar/HomeTitleBar';
|
||||||
import React, { useState, useCallback, useMemo } from 'react';
|
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
||||||
import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild';
|
import { SidebarChildVO } from '@/app/home/components/home-sidebar/HomeSidebarChild';
|
||||||
import { I18nObject } from '@/app/infra/entities/common';
|
import { I18nObject } from '@/app/infra/entities/common';
|
||||||
|
import { userInfo, initializeUserInfo } from '@/app/infra/http';
|
||||||
|
|
||||||
export default function HomeLayout({
|
export default function HomeLayout({
|
||||||
children,
|
children,
|
||||||
@@ -19,6 +20,13 @@ export default function HomeLayout({
|
|||||||
zh_Hans: '',
|
zh_Hans: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initialize user info if not already initialized
|
||||||
|
useEffect(() => {
|
||||||
|
if (!userInfo) {
|
||||||
|
initializeUserInfo();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onSelectedChangeAction = useCallback((child: SidebarChildVO) => {
|
const onSelectedChangeAction = useCallback((child: SidebarChildVO) => {
|
||||||
setTitle(child.name);
|
setTitle(child.name);
|
||||||
setSubtitle(child.description);
|
setSubtitle(child.description);
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ export let systemInfo: ApiRespSystemInfo = {
|
|||||||
disable_models_service: false,
|
disable_models_service: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 用户信息
|
||||||
|
export let userInfo: {
|
||||||
|
user: string;
|
||||||
|
account_type: 'local' | 'space';
|
||||||
|
has_password: boolean;
|
||||||
|
} | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取基础 URL
|
* 获取基础 URL
|
||||||
*/
|
*/
|
||||||
@@ -24,6 +31,8 @@ const getBaseURL = (): string => {
|
|||||||
|
|
||||||
// 创建后端客户端实例
|
// 创建后端客户端实例
|
||||||
export const backendClient = new BackendClient(getBaseURL());
|
export const backendClient = new BackendClient(getBaseURL());
|
||||||
|
// 为了兼容性,也导出为 httpClient
|
||||||
|
export const httpClient = backendClient;
|
||||||
|
|
||||||
// 创建云服务客户端实例(初始化时使用默认 URL)
|
// 创建云服务客户端实例(初始化时使用默认 URL)
|
||||||
export const cloudServiceClient = new CloudServiceClient(
|
export const cloudServiceClient = new CloudServiceClient(
|
||||||
@@ -82,6 +91,27 @@ export const initializeSystemInfo = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化用户信息
|
||||||
|
* 应该在用户登录后调用此方法
|
||||||
|
*/
|
||||||
|
export const initializeUserInfo = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
userInfo = await backendClient.getUserInfo();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize user info:', error);
|
||||||
|
userInfo = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除用户信息
|
||||||
|
* 应该在用户登出时调用此方法
|
||||||
|
*/
|
||||||
|
export const clearUserInfo = (): void => {
|
||||||
|
userInfo = null;
|
||||||
|
};
|
||||||
|
|
||||||
// 导出类型,以便其他地方使用
|
// 导出类型,以便其他地方使用
|
||||||
export type { ResponseData, RequestConfig } from './BaseHttpClient';
|
export type { ResponseData, RequestConfig } from './BaseHttpClient';
|
||||||
export { BaseHttpClient } from './BaseHttpClient';
|
export { BaseHttpClient } from './BaseHttpClient';
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
import { httpClient, initializeUserInfo } from '@/app/infra/http';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { Mail, Lock, Loader2 } from 'lucide-react';
|
import { Mail, Lock, Loader2 } from 'lucide-react';
|
||||||
import langbotIcon from '@/app/assets/langbot-logo.webp';
|
import langbotIcon from '@/app/assets/langbot-logo.webp';
|
||||||
@@ -95,9 +95,10 @@ export default function Login() {
|
|||||||
function handleLogin(username: string, password: string) {
|
function handleLogin(username: string, password: string) {
|
||||||
httpClient
|
httpClient
|
||||||
.authUser(username, password)
|
.authUser(username, password)
|
||||||
.then((res) => {
|
.then(async (res) => {
|
||||||
localStorage.setItem('token', res.token);
|
localStorage.setItem('token', res.token);
|
||||||
localStorage.setItem('userEmail', username);
|
localStorage.setItem('userEmail', username);
|
||||||
|
await initializeUserInfo();
|
||||||
router.push('/home');
|
router.push('/home');
|
||||||
toast.success(t('common.loginSuccess'));
|
toast.success(t('common.loginSuccess'));
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user