Merge branch 'langgenius:main' into fix/manual-metadata-conditon-in-agent

pull/20362/head
suntp 12 months ago committed by GitHub
commit 23b277186b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,12 +2,14 @@ from collections.abc import Callable
from functools import wraps from functools import wraps
from typing import Optional from typing import Optional
from flask import request from flask import current_app, request
from flask_login import user_logged_in
from flask_restful import reqparse from flask_restful import reqparse
from pydantic import BaseModel from pydantic import BaseModel
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from extensions.ext_database import db from extensions.ext_database import db
from libs.login import _get_user
from models.account import Account, Tenant from models.account import Account, Tenant
from models.model import EndUser from models.model import EndUser
from services.account_service import AccountService from services.account_service import AccountService
@ -80,7 +82,12 @@ def get_user_tenant(view: Optional[Callable] = None):
raise ValueError("tenant not found") raise ValueError("tenant not found")
kwargs["tenant_model"] = tenant_model kwargs["tenant_model"] = tenant_model
kwargs["user_model"] = get_user(tenant_id, user_id)
user = get_user(tenant_id, user_id)
kwargs["user_model"] = user
current_app.login_manager._update_request_context_with_user(user) # type: ignore
user_logged_in.send(current_app._get_current_object(), user=_get_user()) # type: ignore
return view_func(*args, **kwargs) return view_func(*args, **kwargs)

@ -356,7 +356,9 @@ class AgentNode(ToolNode):
def _remove_unsupported_model_features_for_old_version(self, model_schema: AIModelEntity) -> AIModelEntity: def _remove_unsupported_model_features_for_old_version(self, model_schema: AIModelEntity) -> AIModelEntity:
if model_schema.features: if model_schema.features:
for feature in model_schema.features: for feature in model_schema.features[:]: # Create a copy to safely modify during iteration
if feature.value not in AgentOldVersionModelFeatures: try:
AgentOldVersionModelFeatures(feature.value) # Try to create enum member from value
except ValueError:
model_schema.features.remove(feature) model_schema.features.remove(feature)
return model_schema return model_schema

@ -1,4 +1,4 @@
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Literal, Union from typing import Any, Literal, Union
from pydantic import BaseModel from pydantic import BaseModel
@ -26,7 +26,7 @@ class ParamsAutoGenerated(Enum):
OPEN = 1 OPEN = 1
class AgentOldVersionModelFeatures(Enum): class AgentOldVersionModelFeatures(StrEnum):
""" """
Enum class for old SDK version llm feature. Enum class for old SDK version llm feature.
""" """

@ -149,6 +149,7 @@ dev = [
"types-tqdm~=4.67.0", "types-tqdm~=4.67.0",
"types-ujson~=5.10.0", "types-ujson~=5.10.0",
"boto3-stubs>=1.38.20", "boto3-stubs>=1.38.20",
"types-jmespath>=1.0.2.20240106",
] ]
############################################################ ############################################################

@ -1315,6 +1315,7 @@ dev = [
{ name = "types-gevent" }, { name = "types-gevent" },
{ name = "types-greenlet" }, { name = "types-greenlet" },
{ name = "types-html5lib" }, { name = "types-html5lib" },
{ name = "types-jmespath" },
{ name = "types-jsonschema" }, { name = "types-jsonschema" },
{ name = "types-markdown" }, { name = "types-markdown" },
{ name = "types-oauthlib" }, { name = "types-oauthlib" },
@ -1486,6 +1487,7 @@ dev = [
{ name = "types-gevent", specifier = "~=24.11.0" }, { name = "types-gevent", specifier = "~=24.11.0" },
{ name = "types-greenlet", specifier = "~=3.1.0" }, { name = "types-greenlet", specifier = "~=3.1.0" },
{ name = "types-html5lib", specifier = "~=1.1.11" }, { name = "types-html5lib", specifier = "~=1.1.11" },
{ name = "types-jmespath", specifier = ">=1.0.2.20240106" },
{ name = "types-jsonschema", specifier = "~=4.23.0" }, { name = "types-jsonschema", specifier = "~=4.23.0" },
{ name = "types-markdown", specifier = "~=3.7.0" }, { name = "types-markdown", specifier = "~=3.7.0" },
{ name = "types-oauthlib", specifier = "~=3.2.0" }, { name = "types-oauthlib", specifier = "~=3.2.0" },
@ -5726,6 +5728,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/ba/7c/f862b1dc31268ef10fe95b43dcdf216ba21a592fafa2d124445cd6b92e93/types_html5lib-1.1.11.20241018-py3-none-any.whl", hash = "sha256:3f1e064d9ed2c289001ae6392c84c93833abb0816165c6ff0abfc304a779f403", size = 17292 }, { url = "https://files.pythonhosted.org/packages/ba/7c/f862b1dc31268ef10fe95b43dcdf216ba21a592fafa2d124445cd6b92e93/types_html5lib-1.1.11.20241018-py3-none-any.whl", hash = "sha256:3f1e064d9ed2c289001ae6392c84c93833abb0816165c6ff0abfc304a779f403", size = 17292 },
] ]
[[package]]
name = "types-jmespath"
version = "1.0.2.20240106"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/1b/e4/1f7414dbca03975f66f1ab1b3f7b3deb7c19b104ef14dd3c99036bbc39b2/types-jmespath-1.0.2.20240106.tar.gz", hash = "sha256:b4a65a116bfc1c700a4fd9d24e2e397f4a431122e0320a77b7f1989a6b5d819e", size = 5071 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/f5/30/3d6443f782601dd88820ba31e7668abfec7e19d685ac7f6fbcfd6ebba519/types_jmespath-1.0.2.20240106-py3-none-any.whl", hash = "sha256:c3e715fcaae9e5f8d74e14328fdedc4f2b3f0e18df17f3e457ae0a18e245bde0", size = 6087 },
]
[[package]] [[package]]
name = "types-jsonschema" name = "types-jsonschema"
version = "4.23.0.20241208" version = "4.23.0.20241208"

@ -40,7 +40,7 @@ const TabSlider: FC<TabSliderProps> = ({
const newIndex = options.findIndex(option => option.value === value) const newIndex = options.findIndex(option => option.value === value)
setActiveIndex(newIndex) setActiveIndex(newIndex)
updateSliderStyle(newIndex) updateSliderStyle(newIndex)
}, [value, options, pluginList]) }, [value, options, pluginList?.total])
return ( return (
<div className={cn(className, 'relative inline-flex items-center justify-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5')}> <div className={cn(className, 'relative inline-flex items-center justify-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5')}>
@ -69,13 +69,13 @@ const TabSlider: FC<TabSliderProps> = ({
{option.text} {option.text}
{/* if no plugin installed, the badge won't show */} {/* if no plugin installed, the badge won't show */}
{option.value === 'plugins' {option.value === 'plugins'
&& (pluginList?.plugins.length ?? 0) > 0 && (pluginList?.total ?? 0) > 0
&& <Badge && <Badge
size='s' size='s'
uppercase={true} uppercase={true}
state={BadgeState.Default} state={BadgeState.Default}
> >
{pluginList?.plugins.length} {pluginList?.total}
</Badge> </Badge>
} }
</div> </div>

@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import type { FilterState } from './filter-management' import type { FilterState } from './filter-management'
import FilterManagement from './filter-management' import FilterManagement from './filter-management'
import List from './list' import List from './list'
import { useInstalledLatestVersion, useInstalledPluginListWithPagination, useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInstalledLatestVersion, useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins'
import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel' import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel'
import { usePluginPageContext } from './context' import { usePluginPageContext } from './context'
import { useDebounceFn } from 'ahooks' import { useDebounceFn } from 'ahooks'
@ -17,7 +17,7 @@ const PluginsPanel = () => {
const { t } = useTranslation() const { t } = useTranslation()
const filters = usePluginPageContext(v => v.filters) as FilterState const filters = usePluginPageContext(v => v.filters) as FilterState
const setFilters = usePluginPageContext(v => v.setFilters) const setFilters = usePluginPageContext(v => v.setFilters)
const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginListWithPagination() const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginList()
const { data: installedLatestVersion } = useInstalledLatestVersion( const { data: installedLatestVersion } = useInstalledLatestVersion(
pluginList?.plugins pluginList?.plugins
.filter(plugin => plugin.source === PluginSource.marketplace) .filter(plugin => plugin.source === PluginSource.marketplace)

@ -10,7 +10,6 @@ import type {
GitHubItemAndMarketPlaceDependency, GitHubItemAndMarketPlaceDependency,
InstallPackageResponse, InstallPackageResponse,
InstalledLatestVersionResponse, InstalledLatestVersionResponse,
InstalledPluginListResponse,
InstalledPluginListWithTotalResponse, InstalledPluginListWithTotalResponse,
PackageDependency, PackageDependency,
Permissions, Permissions,
@ -67,16 +66,7 @@ export const useCheckInstalled = ({
}) })
} }
export const useInstalledPluginList = (disable?: boolean) => { export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => {
return useQuery<InstalledPluginListResponse>({
queryKey: useInstalledPluginListKey,
queryFn: () => get<InstalledPluginListResponse>('/workspaces/current/plugin/list'),
enabled: !disable,
initialData: !disable ? undefined : { plugins: [] },
})
}
export const useInstalledPluginListWithPagination = (pageSize = 100) => {
const fetchPlugins = async ({ pageParam = 1 }) => { const fetchPlugins = async ({ pageParam = 1 }) => {
const response = await get<InstalledPluginListWithTotalResponse>( const response = await get<InstalledPluginListWithTotalResponse>(
`/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`, `/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`,
@ -91,8 +81,10 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
hasNextPage, hasNextPage,
isFetchingNextPage, isFetchingNextPage,
isLoading, isLoading,
isSuccess,
} = useInfiniteQuery({ } = useInfiniteQuery({
queryKey: ['installed-plugins', pageSize], enabled: !disable,
queryKey: useInstalledPluginListKey,
queryFn: fetchPlugins, queryFn: fetchPlugins,
getNextPageParam: (lastPage, pages) => { getNextPageParam: (lastPage, pages) => {
const totalItems = lastPage.total const totalItems = lastPage.total
@ -108,10 +100,12 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
}) })
const plugins = data?.pages.flatMap(page => page.plugins) ?? [] const plugins = data?.pages.flatMap(page => page.plugins) ?? []
const total = data?.pages[0].total ?? 0
return { return {
data: { data: disable ? undefined : {
plugins, plugins,
total,
}, },
isLastPage: !hasNextPage, isLastPage: !hasNextPage,
loadNextPage: () => { loadNextPage: () => {
@ -120,6 +114,7 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
isLoading, isLoading,
isFetching: isFetchingNextPage, isFetching: isFetchingNextPage,
error, error,
isSuccess,
} }
} }

Loading…
Cancel
Save