mirror of
https://github.com/langgenius/dify.git
synced 2026-01-29 23:22:27 +08:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: kenwoodjw <blackxin55+@gmail.com> Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com> Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: zhanluxianshen <zhanluxianshen@163.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: GuanMu <ballmanjq@gmail.com> Co-authored-by: Davide Delbianco <davide.delbianco@outlook.com> Co-authored-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Co-authored-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com> Co-authored-by: Qiang Lee <18018968632@163.com> Co-authored-by: 李强04 <liqiang04@gaotu.cn> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Matri Qi <matrixdom@126.com> Co-authored-by: huayaoyue6 <huayaoyue@163.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: znn <jubinkumarsoni@gmail.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Muke Wang <shaodwaaron@gmail.com> Co-authored-by: wangmuke <wangmuke@kingsware.cn> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Eric Guo <eric.guocz@gmail.com> Co-authored-by: Zhedong Cen <cenzhedong2@126.com> Co-authored-by: jiangbo721 <jiangbo721@163.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: hjlarry <25834719+hjlarry@users.noreply.github.com> Co-authored-by: lxsummer <35754229+lxjustdoit@users.noreply.github.com> Co-authored-by: 湛露先生 <zhanluxianshen@163.com> Co-authored-by: Guangdong Liu <liugddx@gmail.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Yessenia-d <yessenia.contact@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: 17hz <0x149527@gmail.com> Co-authored-by: Amy <1530140574@qq.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Nite Knite <nkCoding@gmail.com> Co-authored-by: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Co-authored-by: Petrus Han <petrus.hanks@gmail.com> Co-authored-by: iamjoel <2120155+iamjoel@users.noreply.github.com> Co-authored-by: Kalo Chin <frog.beepers.0n@icloud.com> Co-authored-by: Ujjwal Maurya <ujjwalsbx@gmail.com> Co-authored-by: Maries <xh001x@hotmail.com>
195 lines
6.3 KiB
TypeScript
195 lines
6.3 KiB
TypeScript
'use client'
|
|
import React, { useMemo, useRef } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import Loading from '@/app/components/base/loading'
|
|
import AppInputsForm from '@/app/components/plugins/plugin-detail-panel/app-selector/app-inputs-form'
|
|
import { useAppDetail } from '@/service/use-apps'
|
|
import { useAppWorkflow } from '@/service/use-workflow'
|
|
import { useFileUploadConfig } from '@/service/use-common'
|
|
import { Resolution } from '@/types/app'
|
|
import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants'
|
|
import type { App } from '@/types/app'
|
|
import type { FileUpload } from '@/app/components/base/features/types'
|
|
import { BlockEnum, InputVarType, SupportUploadFileTypes } from '@/app/components/workflow/types'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
type Props = {
|
|
value?: {
|
|
app_id: string
|
|
inputs: Record<string, any>
|
|
}
|
|
appDetail: App
|
|
onFormChange: (value: Record<string, any>) => void
|
|
}
|
|
|
|
const AppInputsPanel = ({
|
|
value,
|
|
appDetail,
|
|
onFormChange,
|
|
}: Props) => {
|
|
const { t } = useTranslation()
|
|
const inputsRef = useRef<any>(value?.inputs || {})
|
|
const isBasicApp = appDetail.mode !== 'advanced-chat' && appDetail.mode !== 'workflow'
|
|
const { data: fileUploadConfig } = useFileUploadConfig()
|
|
const { data: currentApp, isFetching: isAppLoading } = useAppDetail(appDetail.id)
|
|
const { data: currentWorkflow, isFetching: isWorkflowLoading } = useAppWorkflow(isBasicApp ? '' : appDetail.id)
|
|
const isLoading = isAppLoading || isWorkflowLoading
|
|
|
|
const basicAppFileConfig = useMemo(() => {
|
|
let fileConfig: FileUpload
|
|
if (isBasicApp)
|
|
fileConfig = currentApp?.model_config?.file_upload as FileUpload
|
|
else
|
|
fileConfig = currentWorkflow?.features?.file_upload as FileUpload
|
|
return {
|
|
image: {
|
|
detail: fileConfig?.image?.detail || Resolution.high,
|
|
enabled: !!fileConfig?.image?.enabled,
|
|
number_limits: fileConfig?.image?.number_limits || 3,
|
|
transfer_methods: fileConfig?.image?.transfer_methods || ['local_file', 'remote_url'],
|
|
},
|
|
enabled: !!(fileConfig?.enabled || fileConfig?.image?.enabled),
|
|
allowed_file_types: fileConfig?.allowed_file_types || [SupportUploadFileTypes.image],
|
|
allowed_file_extensions: fileConfig?.allowed_file_extensions || [...FILE_EXTS[SupportUploadFileTypes.image]].map(ext => `.${ext}`),
|
|
allowed_file_upload_methods: fileConfig?.allowed_file_upload_methods || fileConfig?.image?.transfer_methods || ['local_file', 'remote_url'],
|
|
number_limits: fileConfig?.number_limits || fileConfig?.image?.number_limits || 3,
|
|
}
|
|
}, [currentApp?.model_config?.file_upload, currentWorkflow?.features?.file_upload, isBasicApp])
|
|
|
|
const inputFormSchema = useMemo(() => {
|
|
if (!currentApp)
|
|
return []
|
|
let inputFormSchema = []
|
|
if (isBasicApp) {
|
|
inputFormSchema = currentApp.model_config?.user_input_form?.filter((item: any) => !item.external_data_tool).map((item: any) => {
|
|
if (item.paragraph) {
|
|
return {
|
|
...item.paragraph,
|
|
type: 'paragraph',
|
|
required: false,
|
|
}
|
|
}
|
|
if (item.number) {
|
|
return {
|
|
...item.number,
|
|
type: 'number',
|
|
required: false,
|
|
}
|
|
}
|
|
if(item.checkbox) {
|
|
return {
|
|
...item.checkbox,
|
|
type: 'checkbox',
|
|
required: false,
|
|
}
|
|
}
|
|
if (item.select) {
|
|
return {
|
|
...item.select,
|
|
type: 'select',
|
|
required: false,
|
|
}
|
|
}
|
|
|
|
if (item['file-list']) {
|
|
return {
|
|
...item['file-list'],
|
|
type: 'file-list',
|
|
required: false,
|
|
fileUploadConfig,
|
|
}
|
|
}
|
|
|
|
if (item.file) {
|
|
return {
|
|
...item.file,
|
|
type: 'file',
|
|
required: false,
|
|
fileUploadConfig,
|
|
}
|
|
}
|
|
|
|
if (item.json_object) {
|
|
return {
|
|
...item.json_object,
|
|
type: 'json_object',
|
|
}
|
|
}
|
|
|
|
return {
|
|
...item['text-input'],
|
|
type: 'text-input',
|
|
required: false,
|
|
}
|
|
}) || []
|
|
}
|
|
else {
|
|
const startNode = currentWorkflow?.graph?.nodes.find(node => node.data.type === BlockEnum.Start) as any
|
|
inputFormSchema = startNode?.data.variables.map((variable: any) => {
|
|
if (variable.type === InputVarType.multiFiles) {
|
|
return {
|
|
...variable,
|
|
required: false,
|
|
fileUploadConfig,
|
|
}
|
|
}
|
|
|
|
if (variable.type === InputVarType.singleFile) {
|
|
return {
|
|
...variable,
|
|
required: false,
|
|
fileUploadConfig,
|
|
}
|
|
}
|
|
return {
|
|
...variable,
|
|
required: false,
|
|
}
|
|
}) || []
|
|
}
|
|
if ((currentApp.mode === 'completion' || currentApp.mode === 'workflow') && basicAppFileConfig.enabled) {
|
|
inputFormSchema.push({
|
|
label: 'Image Upload',
|
|
variable: '#image#',
|
|
type: InputVarType.singleFile,
|
|
required: false,
|
|
...basicAppFileConfig,
|
|
fileUploadConfig,
|
|
})
|
|
}
|
|
return inputFormSchema || []
|
|
}, [basicAppFileConfig, currentApp, currentWorkflow, fileUploadConfig, isBasicApp])
|
|
|
|
const handleFormChange = (value: Record<string, any>) => {
|
|
inputsRef.current = value
|
|
onFormChange(value)
|
|
}
|
|
|
|
return (
|
|
<div className={cn('flex max-h-[240px] flex-col rounded-b-2xl border-t border-divider-subtle pb-4')}>
|
|
{isLoading && <div className='pt-3'><Loading type='app' /></div>}
|
|
{!isLoading && (
|
|
<div className='system-sm-semibold mb-2 mt-3 flex h-6 shrink-0 items-center px-4 text-text-secondary'>{t('app.appSelector.params')}</div>
|
|
)}
|
|
{!isLoading && !inputFormSchema.length && (
|
|
<div className='flex h-16 flex-col items-center justify-center'>
|
|
<div className='system-sm-regular text-text-tertiary'>{t('app.appSelector.noParams')}</div>
|
|
</div>
|
|
)}
|
|
{!isLoading && !!inputFormSchema.length && (
|
|
<div className='grow overflow-y-auto'>
|
|
<AppInputsForm
|
|
inputs={value?.inputs || {}}
|
|
inputsRef={inputsRef}
|
|
inputsForms={inputFormSchema}
|
|
onFormChange={handleFormChange}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default AppInputsPanel
|