From cefec440706616c8b5551e483f416d9ff040d947 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 18 Mar 2025 11:12:25 +0800 Subject: [PATCH] feat: add app_mode field to app import and model definitions (#15729) Signed-off-by: -LAN- Co-authored-by: twwu --- api/fields/app_fields.py | 1 + api/models/model.py | 2 +- api/services/app_dsl_service.py | 5 ++++- .../components/app/create-app-dialog/app-list/index.tsx | 2 +- web/app/components/app/create-from-dsl-modal/index.tsx | 9 ++++----- web/app/components/explore/app-list/index.tsx | 2 +- web/models/app.ts | 3 ++- web/utils/app-redirection.ts | 4 +++- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/fields/app_fields.py b/api/fields/app_fields.py index eaf684f16a..f42364f110 100644 --- a/api/fields/app_fields.py +++ b/api/fields/app_fields.py @@ -204,6 +204,7 @@ app_import_fields = { "id": fields.String, "status": fields.String, "app_id": fields.String, + "app_mode": fields.String, "current_dsl_version": fields.String, "imported_dsl_version": fields.String, "error": fields.String, diff --git a/api/models/model.py b/api/models/model.py index bf212e8036..0a5256c335 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -82,7 +82,7 @@ class App(Base): tenant_id: Mapped[str] = db.Column(StringUUID, nullable=False) name = db.Column(db.String(255), nullable=False) description = db.Column(db.Text, nullable=False, server_default=db.text("''::character varying")) - mode = db.Column(db.String(255), nullable=False) + mode: Mapped[str] = mapped_column(db.String(255), nullable=False) icon_type = db.Column(db.String(255), nullable=True) # image, emoji icon = db.Column(db.String(255)) icon_background = db.Column(db.String(255)) diff --git a/api/services/app_dsl_service.py b/api/services/app_dsl_service.py index 4ddb56981e..d33d277d4b 100644 --- a/api/services/app_dsl_service.py +++ b/api/services/app_dsl_service.py @@ -55,6 +55,7 @@ class Import(BaseModel): id: str status: ImportStatus app_id: Optional[str] = None + app_mode: Optional[str] = None current_dsl_version: str = CURRENT_DSL_VERSION imported_dsl_version: str = "" error: str = "" @@ -220,7 +221,7 @@ class AppDslService: error="App not found", ) - if app.mode not in [AppMode.WORKFLOW.value, AppMode.ADVANCED_CHAT.value]: + if app.mode not in [AppMode.WORKFLOW, AppMode.ADVANCED_CHAT]: return Import( id=import_id, status=ImportStatus.FAILED, @@ -285,6 +286,7 @@ class AppDslService: id=import_id, status=status, app_id=app.id, + app_mode=app.mode, imported_dsl_version=imported_version, ) @@ -351,6 +353,7 @@ class AppDslService: id=import_id, status=ImportStatus.COMPLETED, app_id=app.id, + app_mode=app.mode, current_dsl_version=CURRENT_DSL_VERSION, imported_dsl_version=data.get("version", "0.1.0"), ) diff --git a/web/app/components/app/create-app-dialog/app-list/index.tsx b/web/app/components/app/create-app-dialog/app-list/index.tsx index 69990f9311..091e32ed54 100644 --- a/web/app/components/app/create-app-dialog/app-list/index.tsx +++ b/web/app/components/app/create-app-dialog/app-list/index.tsx @@ -151,7 +151,7 @@ const Apps = ({ if (app.app_id) await handleCheckPluginDependencies(app.app_id) localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') - getRedirection(isCurrentWorkspaceEditor, { id: app.app_id, mode }, push) + getRedirection(isCurrentWorkspaceEditor, { id: app.app_id!, mode }, push) } catch (e) { Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) diff --git a/web/app/components/app/create-from-dsl-modal/index.tsx b/web/app/components/app/create-from-dsl-modal/index.tsx index 26e175eb56..c975cd697b 100644 --- a/web/app/components/app/create-from-dsl-modal/index.tsx +++ b/web/app/components/app/create-from-dsl-modal/index.tsx @@ -102,8 +102,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS if (!response) return - - const { id, status, app_id, imported_dsl_version, current_dsl_version } = response + const { id, status, app_id, app_mode, imported_dsl_version, current_dsl_version } = response if (status === DSLImportStatus.COMPLETED || status === DSLImportStatus.COMPLETED_WITH_WARNINGS) { if (onSuccess) onSuccess() @@ -118,7 +117,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') if (app_id) await handleCheckPluginDependencies(app_id) - getRedirection(isCurrentWorkspaceEditor, { id: app_id }, push) + getRedirection(isCurrentWorkspaceEditor, { id: app_id!, mode: app_mode }, push) } else if (status === DSLImportStatus.PENDING) { setVersions({ @@ -151,7 +150,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS import_id: importId, }) - const { status, app_id } = response + const { status, app_id, app_mode } = response if (status === DSLImportStatus.COMPLETED) { if (onSuccess) @@ -166,7 +165,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS if (app_id) await handleCheckPluginDependencies(app_id) localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') - getRedirection(isCurrentWorkspaceEditor, { id: app_id }, push) + getRedirection(isCurrentWorkspaceEditor, { id: app_id!, mode: app_mode }, push) } else if (status === DSLImportStatus.FAILED) { notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx index df15348dd3..a1a2bafd71 100644 --- a/web/app/components/explore/app-list/index.tsx +++ b/web/app/components/explore/app-list/index.tsx @@ -146,7 +146,7 @@ const Apps = ({ if (app.app_id) await handleCheckPluginDependencies(app.app_id) localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') - getRedirection(isCurrentWorkspaceEditor, { id: app.app_id, mode }, push) + getRedirection(isCurrentWorkspaceEditor, { id: app.app_id!, mode }, push) } catch (e) { Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) diff --git a/web/models/app.ts b/web/models/app.ts index b6094b85e9..737df6bfae 100644 --- a/web/models/app.ts +++ b/web/models/app.ts @@ -1,5 +1,5 @@ import type { LangFuseConfig, LangSmithConfig, OpikConfig, TracingProvider } from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type' -import type { App, AppSSO, AppTemplate, SiteConfig } from '@/types/app' +import type { App, AppMode, AppSSO, AppTemplate, SiteConfig } from '@/types/app' import type { Dependency } from '@/app/components/plugins/types' /* export type App = { @@ -84,6 +84,7 @@ export type AppDetailResponse = App export type DSLImportResponse = { id: string status: DSLImportStatus + app_mode: AppMode app_id?: string current_dsl_version?: string imported_dsl_version?: string diff --git a/web/utils/app-redirection.ts b/web/utils/app-redirection.ts index 534b019250..93273129dc 100644 --- a/web/utils/app-redirection.ts +++ b/web/utils/app-redirection.ts @@ -1,6 +1,8 @@ +import type { AppMode } from '@/types/app' + export const getRedirection = ( isCurrentWorkspaceEditor: boolean, - app: any, + app: { id: string, mode: AppMode }, redirectionFunc: (href: string) => void, ) => { if (!isCurrentWorkspaceEditor) {