From 00199c41bbe47f1273370d090803c1d88282f2b3 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 28 May 2025 17:45:08 +0800 Subject: [PATCH 1/3] fix: workflow plugins list update (#20357) --- web/app/components/base/tab-slider/index.tsx | 6 +++--- .../plugins/plugin-page/plugins-panel.tsx | 4 ++-- web/service/use-plugins.ts | 21 +++++++------------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/web/app/components/base/tab-slider/index.tsx b/web/app/components/base/tab-slider/index.tsx index fd6b876d02..56cde52154 100644 --- a/web/app/components/base/tab-slider/index.tsx +++ b/web/app/components/base/tab-slider/index.tsx @@ -40,7 +40,7 @@ const TabSlider: FC = ({ const newIndex = options.findIndex(option => option.value === value) setActiveIndex(newIndex) updateSliderStyle(newIndex) - }, [value, options, pluginList]) + }, [value, options, pluginList?.total]) return (
@@ -69,13 +69,13 @@ const TabSlider: FC = ({ {option.text} {/* if no plugin installed, the badge won't show */} {option.value === 'plugins' - && (pluginList?.plugins.length ?? 0) > 0 + && (pluginList?.total ?? 0) > 0 && - {pluginList?.plugins.length} + {pluginList?.total} }
diff --git a/web/app/components/plugins/plugin-page/plugins-panel.tsx b/web/app/components/plugins/plugin-page/plugins-panel.tsx index 513641f4b9..a5f411c37e 100644 --- a/web/app/components/plugins/plugin-page/plugins-panel.tsx +++ b/web/app/components/plugins/plugin-page/plugins-panel.tsx @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next' import type { FilterState } from './filter-management' import FilterManagement from './filter-management' 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 { usePluginPageContext } from './context' import { useDebounceFn } from 'ahooks' @@ -17,7 +17,7 @@ const PluginsPanel = () => { const { t } = useTranslation() const filters = usePluginPageContext(v => v.filters) as FilterState 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( pluginList?.plugins .filter(plugin => plugin.source === PluginSource.marketplace) diff --git a/web/service/use-plugins.ts b/web/service/use-plugins.ts index 871b6f0649..ecfdbcf993 100644 --- a/web/service/use-plugins.ts +++ b/web/service/use-plugins.ts @@ -10,7 +10,6 @@ import type { GitHubItemAndMarketPlaceDependency, InstallPackageResponse, InstalledLatestVersionResponse, - InstalledPluginListResponse, InstalledPluginListWithTotalResponse, PackageDependency, Permissions, @@ -67,16 +66,7 @@ export const useCheckInstalled = ({ }) } -export const useInstalledPluginList = (disable?: boolean) => { - return useQuery({ - queryKey: useInstalledPluginListKey, - queryFn: () => get('/workspaces/current/plugin/list'), - enabled: !disable, - initialData: !disable ? undefined : { plugins: [] }, - }) -} - -export const useInstalledPluginListWithPagination = (pageSize = 100) => { +export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => { const fetchPlugins = async ({ pageParam = 1 }) => { const response = await get( `/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`, @@ -91,8 +81,10 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { hasNextPage, isFetchingNextPage, isLoading, + isSuccess, } = useInfiniteQuery({ - queryKey: ['installed-plugins', pageSize], + enabled: !disable, + queryKey: useInstalledPluginListKey, queryFn: fetchPlugins, getNextPageParam: (lastPage, pages) => { const totalItems = lastPage.total @@ -108,10 +100,12 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { }) const plugins = data?.pages.flatMap(page => page.plugins) ?? [] + const total = data?.pages[0].total ?? 0 return { - data: { + data: disable ? undefined : { plugins, + total, }, isLastPage: !hasNextPage, loadNextPage: () => { @@ -120,6 +114,7 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => { isLoading, isFetching: isFetchingNextPage, error, + isSuccess, } } From f59fb94dae8c989aa8a6ba92519fd48bb83687d7 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 28 May 2025 19:56:17 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(agent=5Fnode):=20ensure=20that=20the?= =?UTF-8?q?=20enum-checking=20syntax=20is=20compatible=20with=20Python?= =?UTF-8?q?=E2=80=AF3.11.=20(#20373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: -LAN- --- api/core/workflow/nodes/agent/agent_node.py | 6 ++++-- api/core/workflow/nodes/agent/entities.py | 4 ++-- api/pyproject.toml | 1 + api/uv.lock | 11 +++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/core/workflow/nodes/agent/agent_node.py b/api/core/workflow/nodes/agent/agent_node.py index 771e0ca7a5..9bed8862fc 100644 --- a/api/core/workflow/nodes/agent/agent_node.py +++ b/api/core/workflow/nodes/agent/agent_node.py @@ -356,7 +356,9 @@ class AgentNode(ToolNode): def _remove_unsupported_model_features_for_old_version(self, model_schema: AIModelEntity) -> AIModelEntity: if model_schema.features: - for feature in model_schema.features: - if feature.value not in AgentOldVersionModelFeatures: + for feature in model_schema.features[:]: # Create a copy to safely modify during iteration + try: + AgentOldVersionModelFeatures(feature.value) # Try to create enum member from value + except ValueError: model_schema.features.remove(feature) return model_schema diff --git a/api/core/workflow/nodes/agent/entities.py b/api/core/workflow/nodes/agent/entities.py index 77e94375bf..075a41fb2f 100644 --- a/api/core/workflow/nodes/agent/entities.py +++ b/api/core/workflow/nodes/agent/entities.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import Enum, StrEnum from typing import Any, Literal, Union from pydantic import BaseModel @@ -26,7 +26,7 @@ class ParamsAutoGenerated(Enum): OPEN = 1 -class AgentOldVersionModelFeatures(Enum): +class AgentOldVersionModelFeatures(StrEnum): """ Enum class for old SDK version llm feature. """ diff --git a/api/pyproject.toml b/api/pyproject.toml index 1c6adb6587..50a765c0e1 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -149,6 +149,7 @@ dev = [ "types-tqdm~=4.67.0", "types-ujson~=5.10.0", "boto3-stubs>=1.38.20", + "types-jmespath>=1.0.2.20240106", ] ############################################################ diff --git a/api/uv.lock b/api/uv.lock index 033dc8762b..a1e1d6146a 100644 --- a/api/uv.lock +++ b/api/uv.lock @@ -1315,6 +1315,7 @@ dev = [ { name = "types-gevent" }, { name = "types-greenlet" }, { name = "types-html5lib" }, + { name = "types-jmespath" }, { name = "types-jsonschema" }, { name = "types-markdown" }, { name = "types-oauthlib" }, @@ -1486,6 +1487,7 @@ dev = [ { name = "types-gevent", specifier = "~=24.11.0" }, { name = "types-greenlet", specifier = "~=3.1.0" }, { name = "types-html5lib", specifier = "~=1.1.11" }, + { name = "types-jmespath", specifier = ">=1.0.2.20240106" }, { name = "types-jsonschema", specifier = "~=4.23.0" }, { name = "types-markdown", specifier = "~=3.7.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 }, ] +[[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]] name = "types-jsonschema" version = "4.23.0.20241208" From c3c67d9608c1d0eba45473a86543f5049df69fe2 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 28 May 2025 19:56:33 +0800 Subject: [PATCH 3/3] fix: register user model to current_user in backward invoke. (#20374) Signed-off-by: -LAN- --- api/controllers/inner_api/plugin/wraps.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/controllers/inner_api/plugin/wraps.py b/api/controllers/inner_api/plugin/wraps.py index 709bba3f30..b2849a7962 100644 --- a/api/controllers/inner_api/plugin/wraps.py +++ b/api/controllers/inner_api/plugin/wraps.py @@ -2,12 +2,14 @@ from collections.abc import Callable from functools import wraps 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 pydantic import BaseModel from sqlalchemy.orm import Session from extensions.ext_database import db +from libs.login import _get_user from models.account import Account, Tenant from models.model import EndUser from services.account_service import AccountService @@ -80,7 +82,12 @@ def get_user_tenant(view: Optional[Callable] = None): raise ValueError("tenant not found") 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)