fix features update by DSL import

This commit is contained in:
JzoNg 2024-09-29 17:15:39 +08:00
parent f0285a53d2
commit e2b1464db2
2 changed files with 31 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import { createStore } from 'zustand'
import type { Features } from './types'
import { TransferMethod } from '@/types/app'
import { Resolution, TransferMethod } from '@/types/app'
export type FeaturesModal = {
showFeaturesModal: boolean
@ -46,7 +46,7 @@ export const createFeaturesStore = (initProps?: Partial<FeaturesState>) => {
file: {
image: {
enabled: false,
detail: 'high',
detail: Resolution.high,
number_limits: 3,
transfer_methods: [TransferMethod.local_file, TransferMethod.remote_url],
},

View File

@ -14,6 +14,9 @@ import {
RiCloseLine,
} from '@remixicon/react'
import { WORKFLOW_DATA_UPDATE } from './constants'
import {
SupportUploadFileTypes,
} from './types'
import {
initialEdges,
initialNodes,
@ -25,6 +28,7 @@ import { ToastContext } from '@/app/components/base/toast'
import { updateWorkflowDraftFromDSL } from '@/service/workflow'
import { useEventEmitterContextContext } from '@/context/event-emitter'
import { useStore as useAppStore } from '@/app/components/app/store'
import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants'
type UpdateDSLModalProps = {
onCancel: () => void
@ -78,13 +82,37 @@ const UpdateDSLModal = ({
hash,
} = await updateWorkflowDraftFromDSL(appDetail.id, fileContent)
const { nodes, edges, viewport } = graph
const newFeatures = {
file: {
image: {
enabled: !!features.file_upload?.image?.enabled,
number_limits: features.file_upload?.image?.number_limits || 3,
transfer_methods: features.file_upload?.image?.transfer_methods || ['local_file', 'remote_url'],
},
enabled: !!(features.file_upload?.enabled || features.file_upload?.image?.enabled),
allowed_file_types: features.file_upload?.allowed_file_types || [SupportUploadFileTypes.image],
allowed_file_extensions: features.file_upload?.allowed_file_extensions || FILE_EXTS[SupportUploadFileTypes.image].map(ext => `.${ext}`),
allowed_file_upload_methods: features.file_upload?.allowed_file_upload_methods || features.file_upload?.image?.transfer_methods || ['local_file', 'remote_url'],
number_limits: features.file_upload?.number_limits || features.file_upload?.image?.number_limits || 3,
},
opening: {
enabled: !!features.opening_statement,
opening_statement: features.opening_statement,
suggested_questions: features.suggested_questions,
},
suggested: features.suggested_questions_after_answer || { enabled: false },
speech2text: features.speech_to_text || { enabled: false },
text2speech: features.text_to_speech || { enabled: false },
citation: features.retriever_resource || { enabled: false },
moderation: features.sensitive_word_avoidance || { enabled: false },
}
eventEmitter?.emit({
type: WORKFLOW_DATA_UPDATE,
payload: {
nodes: initialNodes(nodes, edges),
edges: initialEdges(edges, nodes),
viewport,
features,
features: newFeatures,
hash,
},
} as any)