feat: add app_mode field to app import and model definitions (#15729)

Signed-off-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: twwu <twwu@dify.ai>
This commit is contained in:
-LAN- 2025-03-18 11:12:25 +08:00 committed by GitHub
parent 20376ca951
commit cefec44070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 11 deletions

View File

@ -204,6 +204,7 @@ app_import_fields = {
"id": fields.String, "id": fields.String,
"status": fields.String, "status": fields.String,
"app_id": fields.String, "app_id": fields.String,
"app_mode": fields.String,
"current_dsl_version": fields.String, "current_dsl_version": fields.String,
"imported_dsl_version": fields.String, "imported_dsl_version": fields.String,
"error": fields.String, "error": fields.String,

View File

@ -82,7 +82,7 @@ class App(Base):
tenant_id: Mapped[str] = db.Column(StringUUID, nullable=False) tenant_id: Mapped[str] = db.Column(StringUUID, nullable=False)
name = db.Column(db.String(255), nullable=False) name = db.Column(db.String(255), nullable=False)
description = db.Column(db.Text, nullable=False, server_default=db.text("''::character varying")) 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_type = db.Column(db.String(255), nullable=True) # image, emoji
icon = db.Column(db.String(255)) icon = db.Column(db.String(255))
icon_background = db.Column(db.String(255)) icon_background = db.Column(db.String(255))

View File

@ -55,6 +55,7 @@ class Import(BaseModel):
id: str id: str
status: ImportStatus status: ImportStatus
app_id: Optional[str] = None app_id: Optional[str] = None
app_mode: Optional[str] = None
current_dsl_version: str = CURRENT_DSL_VERSION current_dsl_version: str = CURRENT_DSL_VERSION
imported_dsl_version: str = "" imported_dsl_version: str = ""
error: str = "" error: str = ""
@ -220,7 +221,7 @@ class AppDslService:
error="App not found", 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( return Import(
id=import_id, id=import_id,
status=ImportStatus.FAILED, status=ImportStatus.FAILED,
@ -285,6 +286,7 @@ class AppDslService:
id=import_id, id=import_id,
status=status, status=status,
app_id=app.id, app_id=app.id,
app_mode=app.mode,
imported_dsl_version=imported_version, imported_dsl_version=imported_version,
) )
@ -351,6 +353,7 @@ class AppDslService:
id=import_id, id=import_id,
status=ImportStatus.COMPLETED, status=ImportStatus.COMPLETED,
app_id=app.id, app_id=app.id,
app_mode=app.mode,
current_dsl_version=CURRENT_DSL_VERSION, current_dsl_version=CURRENT_DSL_VERSION,
imported_dsl_version=data.get("version", "0.1.0"), imported_dsl_version=data.get("version", "0.1.0"),
) )

View File

@ -151,7 +151,7 @@ const Apps = ({
if (app.app_id) if (app.app_id)
await handleCheckPluginDependencies(app.app_id) await handleCheckPluginDependencies(app.app_id)
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') 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) { catch (e) {
Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') })

View File

@ -102,8 +102,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS
if (!response) if (!response)
return return
const { id, status, app_id, app_mode, imported_dsl_version, current_dsl_version } = response
const { id, status, app_id, imported_dsl_version, current_dsl_version } = response
if (status === DSLImportStatus.COMPLETED || status === DSLImportStatus.COMPLETED_WITH_WARNINGS) { if (status === DSLImportStatus.COMPLETED || status === DSLImportStatus.COMPLETED_WITH_WARNINGS) {
if (onSuccess) if (onSuccess)
onSuccess() onSuccess()
@ -118,7 +117,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
if (app_id) if (app_id)
await handleCheckPluginDependencies(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) { else if (status === DSLImportStatus.PENDING) {
setVersions({ setVersions({
@ -151,7 +150,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS
import_id: importId, import_id: importId,
}) })
const { status, app_id } = response const { status, app_id, app_mode } = response
if (status === DSLImportStatus.COMPLETED) { if (status === DSLImportStatus.COMPLETED) {
if (onSuccess) if (onSuccess)
@ -166,7 +165,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose, activeTab = CreateFromDS
if (app_id) if (app_id)
await handleCheckPluginDependencies(app_id) await handleCheckPluginDependencies(app_id)
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') 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) { else if (status === DSLImportStatus.FAILED) {
notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) notify({ type: 'error', message: t('app.newApp.appCreateFailed') })

View File

@ -146,7 +146,7 @@ const Apps = ({
if (app.app_id) if (app.app_id)
await handleCheckPluginDependencies(app.app_id) await handleCheckPluginDependencies(app.app_id)
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') 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) { catch (e) {
Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') })

View File

@ -1,5 +1,5 @@
import type { LangFuseConfig, LangSmithConfig, OpikConfig, TracingProvider } from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type' 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' import type { Dependency } from '@/app/components/plugins/types'
/* export type App = { /* export type App = {
@ -84,6 +84,7 @@ export type AppDetailResponse = App
export type DSLImportResponse = { export type DSLImportResponse = {
id: string id: string
status: DSLImportStatus status: DSLImportStatus
app_mode: AppMode
app_id?: string app_id?: string
current_dsl_version?: string current_dsl_version?: string
imported_dsl_version?: string imported_dsl_version?: string

View File

@ -1,6 +1,8 @@
import type { AppMode } from '@/types/app'
export const getRedirection = ( export const getRedirection = (
isCurrentWorkspaceEditor: boolean, isCurrentWorkspaceEditor: boolean,
app: any, app: { id: string, mode: AppMode },
redirectionFunc: (href: string) => void, redirectionFunc: (href: string) => void,
) => { ) => {
if (!isCurrentWorkspaceEditor) { if (!isCurrentWorkspaceEditor) {