chore(web): new lint setup (#30020)

Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
This commit is contained in:
Stephen Zhou
2025-12-23 16:58:55 +08:00
committed by GitHub
parent 9701a2994b
commit f2842da397
3356 changed files with 85046 additions and 81278 deletions

View File

@ -1,46 +1,46 @@
'use client'
import type { FC } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
RiBookmark3Line,
RiErrorWarningFill,
} from '@remixicon/react'
import { useBoolean } from 'ahooks'
import { useSearchParams } from 'next/navigation'
import TabHeader from '../../base/tab-header'
import MenuDropdown from './menu-dropdown'
import RunBatch from './run-batch'
import ResDownload from './run-batch/res-download'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import RunOnce from '@/app/components/share/text-generation/run-once'
import { fetchSavedMessage as doFetchSavedMessage, removeMessage, saveMessage } from '@/service/share'
import type { SiteInfo } from '@/models/share'
import type {
MoreLikeThisConfig,
PromptConfig,
SavedMessage,
TextToSpeechConfig,
} from '@/models/debug'
import type { InstalledApp } from '@/models/explore'
import type { SiteInfo } from '@/models/share'
import type { VisionFile, VisionSettings } from '@/types/app'
import {
RiBookmark3Line,
RiErrorWarningFill,
} from '@remixicon/react'
import { useBoolean } from 'ahooks'
import { useSearchParams } from 'next/navigation'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import SavedItems from '@/app/components/app/text-generate/saved-items'
import AppIcon from '@/app/components/base/app-icon'
import Badge from '@/app/components/base/badge'
import { changeLanguage } from '@/i18n-config/i18next-config'
import Loading from '@/app/components/base/loading'
import { userInputsFormToPromptVariables } from '@/utils/model-config'
import Res from '@/app/components/share/text-generation/result'
import SavedItems from '@/app/components/app/text-generate/saved-items'
import type { InstalledApp } from '@/models/explore'
import { DEFAULT_VALUE_MAX_LEN, appDefaultIconBackground } from '@/config'
import Toast from '@/app/components/base/toast'
import type { VisionFile, VisionSettings } from '@/types/app'
import { Resolution, TransferMethod } from '@/types/app'
import { useAppFavicon } from '@/hooks/use-app-favicon'
import DifyLogo from '@/app/components/base/logo/dify-logo'
import { cn } from '@/utils/classnames'
import { AccessMode } from '@/models/access-control'
import Toast from '@/app/components/base/toast'
import Res from '@/app/components/share/text-generation/result'
import RunOnce from '@/app/components/share/text-generation/run-once'
import { appDefaultIconBackground, DEFAULT_VALUE_MAX_LEN } from '@/config'
import { useGlobalPublicStore } from '@/context/global-public-context'
import useDocumentTitle from '@/hooks/use-document-title'
import { useWebAppStore } from '@/context/web-app-context'
import { useAppFavicon } from '@/hooks/use-app-favicon'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import useDocumentTitle from '@/hooks/use-document-title'
import { changeLanguage } from '@/i18n-config/i18next-config'
import { AccessMode } from '@/models/access-control'
import { fetchSavedMessage as doFetchSavedMessage, removeMessage, saveMessage } from '@/service/share'
import { Resolution, TransferMethod } from '@/types/app'
import { cn } from '@/utils/classnames'
import { userInputsFormToPromptVariables } from '@/utils/model-config'
import TabHeader from '../../base/tab-header'
import MenuDropdown from './menu-dropdown'
import RunBatch from './run-batch'
import ResDownload from './run-batch/res-download'
const GROUP_SIZE = 5 // to avoid RPM(Request per minute) limit. The group task finished then the next group.
enum TaskStatus {
@ -125,7 +125,7 @@ const TextGeneration: FC<IMainProps> = ({
transfer_methods: [TransferMethod.local_file],
})
const [completionFiles, setCompletionFiles] = useState<VisionFile[]>([])
const [runControl, setRunControl] = useState<{ onStop: () => Promise<void> | void; isStopping: boolean } | null>(null)
const [runControl, setRunControl] = useState<{ onStop: () => Promise<void> | void, isStopping: boolean } | null>(null)
useEffect(() => {
if (isCallBatchAPI)
@ -416,34 +416,36 @@ const TextGeneration: FC<IMainProps> = ({
}
const [resultExisted, setResultExisted] = useState(false)
const renderRes = (task?: Task) => (<Res
key={task?.id}
isWorkflow={isWorkflow}
isCallBatchAPI={isCallBatchAPI}
isPC={isPC}
isMobile={!isPC}
isInstalledApp={isInstalledApp}
appId={appId}
installedAppInfo={installedAppInfo}
isError={task?.status === TaskStatus.failed}
promptConfig={promptConfig}
moreLikeThisEnabled={!!moreLikeThisConfig?.enabled}
inputs={isCallBatchAPI ? (task as Task).params.inputs : inputs}
controlSend={controlSend}
controlRetry={task?.status === TaskStatus.failed ? controlRetry : 0}
controlStopResponding={controlStopResponding}
onShowRes={showResultPanel}
handleSaveMessage={handleSaveMessage}
taskId={task?.id}
onCompleted={handleCompleted}
visionConfig={visionConfig}
completionFiles={completionFiles}
isShowTextToSpeech={!!textToSpeechConfig?.enabled}
siteInfo={siteInfo}
onRunStart={() => setResultExisted(true)}
onRunControlChange={!isCallBatchAPI ? setRunControl : undefined}
hideInlineStopButton={!isCallBatchAPI}
/>)
const renderRes = (task?: Task) => (
<Res
key={task?.id}
isWorkflow={isWorkflow}
isCallBatchAPI={isCallBatchAPI}
isPC={isPC}
isMobile={!isPC}
isInstalledApp={isInstalledApp}
appId={appId}
installedAppInfo={installedAppInfo}
isError={task?.status === TaskStatus.failed}
promptConfig={promptConfig}
moreLikeThisEnabled={!!moreLikeThisConfig?.enabled}
inputs={isCallBatchAPI ? (task as Task).params.inputs : inputs}
controlSend={controlSend}
controlRetry={task?.status === TaskStatus.failed ? controlRetry : 0}
controlStopResponding={controlStopResponding}
onShowRes={showResultPanel}
handleSaveMessage={handleSaveMessage}
taskId={task?.id}
onCompleted={handleCompleted}
visionConfig={visionConfig}
completionFiles={completionFiles}
isShowTextToSpeech={!!textToSpeechConfig?.enabled}
siteInfo={siteInfo}
onRunStart={() => setResultExisted(true)}
onRunControlChange={!isCallBatchAPI ? setRunControl : undefined}
hideInlineStopButton={!isCallBatchAPI}
/>
)
const renderBatchRes = () => {
return (showTaskList.map(task => renderRes(task)))
@ -465,8 +467,9 @@ const TextGeneration: FC<IMainProps> = ({
<div className={cn(
'flex shrink-0 items-center justify-between px-14 pb-2 pt-9',
!isPC && 'px-4 pb-1 pt-3',
)}>
<div className='system-md-semibold-uppercase text-text-primary'>{t('share.generation.executions', { num: allTaskList.length })}</div>
)}
>
<div className="system-md-semibold-uppercase text-text-primary">{t('share.generation.executions', { num: allTaskList.length })}</div>
{allSuccessTaskList.length > 0 && (
<ResDownload
isMobile={!isPC}
@ -480,20 +483,21 @@ const TextGeneration: FC<IMainProps> = ({
isPC && 'px-14 py-8',
isPC && isCallBatchAPI && 'pt-0',
!isPC && 'p-0 pb-2',
)}>
)}
>
{!isCallBatchAPI ? renderRes() : renderBatchRes()}
{!noPendingTask && (
<div className='mt-4'>
<Loading type='area' />
<div className="mt-4">
<Loading type="area" />
</div>
)}
</div>
{isCallBatchAPI && allFailedTaskList.length > 0 && (
<div className='absolute bottom-6 left-1/2 z-10 flex -translate-x-1/2 items-center gap-2 rounded-xl border border-components-panel-border bg-components-panel-bg-blur p-3 shadow-lg backdrop-blur-sm'>
<RiErrorWarningFill className='h-4 w-4 text-text-destructive' />
<div className='system-sm-medium text-text-secondary'>{t('share.generation.batchFailed.info', { num: allFailedTaskList.length })}</div>
<div className='h-3.5 w-px bg-divider-regular'></div>
<div onClick={handleRetryAllFailedTask} className='system-sm-semibold-uppercase cursor-pointer text-text-accent'>{t('share.generation.batchFailed.retry')}</div>
<div className="absolute bottom-6 left-1/2 z-10 flex -translate-x-1/2 items-center gap-2 rounded-xl border border-components-panel-border bg-components-panel-bg-blur p-3 shadow-lg backdrop-blur-sm">
<RiErrorWarningFill className="h-4 w-4 text-text-destructive" />
<div className="system-sm-medium text-text-secondary">{t('share.generation.batchFailed.info', { num: allFailedTaskList.length })}</div>
<div className="h-3.5 w-px bg-divider-regular"></div>
<div onClick={handleRetryAllFailedTask} className="system-sm-semibold-uppercase cursor-pointer text-text-accent">{t('share.generation.batchFailed.retry')}</div>
</div>
)}
</div>
@ -501,9 +505,10 @@ const TextGeneration: FC<IMainProps> = ({
if (!appId || !siteInfo || !promptConfig) {
return (
<div className='flex h-screen items-center'>
<Loading type='app' />
</div>)
<div className="flex h-screen items-center">
<Loading type="app" />
</div>
)
}
return (
<div className={cn(
@ -511,16 +516,18 @@ const TextGeneration: FC<IMainProps> = ({
isPC && 'flex',
!isPC && 'flex-col',
isInstalledApp ? 'h-full rounded-2xl shadow-md' : 'h-screen',
)}>
)}
>
{/* Left */}
<div className={cn(
'relative flex h-full shrink-0 flex-col',
isPC ? 'w-[600px] max-w-[50%]' : resultExisted ? 'h-[calc(100%_-_64px)]' : '',
isInstalledApp && 'rounded-l-2xl',
)}>
)}
>
{/* header */}
<div className={cn('shrink-0 space-y-4 border-b border-divider-subtle', isPC ? 'bg-components-panel-bg p-8 pb-0' : 'p-4 pb-0')}>
<div className='flex items-center gap-3'>
<div className="flex items-center gap-3">
<AppIcon
size={isPC ? 'large' : 'small'}
iconType={siteInfo.icon_type}
@ -528,11 +535,11 @@ const TextGeneration: FC<IMainProps> = ({
background={siteInfo.icon_background || appDefaultIconBackground}
imageUrl={siteInfo.icon_url}
/>
<div className='system-md-semibold grow truncate text-text-secondary'>{siteInfo.title}</div>
<div className="system-md-semibold grow truncate text-text-secondary">{siteInfo.title}</div>
<MenuDropdown hideLogout={isInstalledApp || accessMode === AccessMode.PUBLIC} data={siteInfo} />
</div>
{siteInfo.description && (
<div className='system-xs-regular text-text-tertiary'>{siteInfo.description}</div>
<div className="system-xs-regular text-text-tertiary">{siteInfo.description}</div>
)}
<TabHeader
items={[
@ -540,18 +547,18 @@ const TextGeneration: FC<IMainProps> = ({
{ id: 'batch', name: t('share.generation.tabs.batch') },
...(!isWorkflow
? [{
id: 'saved',
name: t('share.generation.tabs.saved'),
isRight: true,
icon: <RiBookmark3Line className='h-4 w-4' />,
extra: savedMessages.length > 0
? (
<Badge className='ml-1'>
{savedMessages.length}
</Badge>
)
: null,
}]
id: 'saved',
name: t('share.generation.tabs.saved'),
isRight: true,
icon: <RiBookmark3Line className="h-4 w-4" />,
extra: savedMessages.length > 0
? (
<Badge className="ml-1">
{savedMessages.length}
</Badge>
)
: null,
}]
: []),
]}
value={currentTab}
@ -563,7 +570,8 @@ const TextGeneration: FC<IMainProps> = ({
'h-0 grow overflow-y-auto bg-components-panel-bg',
isPC ? 'px-8' : 'px-4',
!isPC && resultExisted && customConfig?.remove_webapp_brand && 'rounded-b-2xl border-b-[0.5px] border-divider-regular',
)}>
)}
>
<div className={cn(currentTab === 'create' ? 'block' : 'hidden')}>
<RunOnce
siteInfo={siteInfo}
@ -600,14 +608,15 @@ const TextGeneration: FC<IMainProps> = ({
'flex shrink-0 items-center gap-1.5 bg-components-panel-bg py-3',
isPC ? 'px-8' : 'px-4',
!isPC && resultExisted && 'rounded-b-2xl border-b-[0.5px] border-divider-regular',
)}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
)}
>
<div className="system-2xs-medium-uppercase text-text-tertiary">{t('share.chat.poweredBy')}</div>
{
systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
? <img src={systemFeatures.branding.workspace_logo} alt="logo" className="block h-5 w-auto" />
: customConfig?.replace_webapp_logo
? <img src={`${customConfig?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
? <img src={`${customConfig?.replace_webapp_logo}`} alt="logo" className="block h-5 w-auto" />
: <DifyLogo size="small" />
}
</div>
)}
@ -621,7 +630,8 @@ const TextGeneration: FC<IMainProps> = ({
: resultExisted
? 'relative h-16 shrink-0 overflow-hidden bg-background-default-burn pt-2.5'
: '',
)}>
)}
>
{!isPC && (
<div
className={cn(
@ -636,7 +646,7 @@ const TextGeneration: FC<IMainProps> = ({
showResultPanel()
}}
>
<div className='h-1 w-8 cursor-grab rounded bg-divider-solid' />
<div className="h-1 w-8 cursor-grab rounded bg-divider-solid" />
</div>
)}
{renderResWrap}

View File

@ -1,9 +1,9 @@
import React from 'react'
import { cn } from '@/utils/classnames'
import Modal from '@/app/components/base/modal'
import AppIcon from '@/app/components/base/app-icon'
import type { SiteInfo } from '@/models/share'
import React from 'react'
import AppIcon from '@/app/components/base/app-icon'
import Modal from '@/app/components/base/modal'
import { appDefaultIconBackground } from '@/config'
import { cn } from '@/utils/classnames'
type Props = {
data?: SiteInfo
@ -20,25 +20,30 @@ const InfoModal = ({
<Modal
isShow={isShow}
onClose={onClose}
className='min-w-[400px] max-w-[400px] !p-0'
className="min-w-[400px] max-w-[400px] !p-0"
closable
>
<div className={cn('flex flex-col items-center gap-4 px-4 pb-8 pt-10')}>
<AppIcon
size='xxl'
size="xxl"
iconType={data?.icon_type}
icon={data?.icon}
background={data?.icon_background || appDefaultIconBackground}
imageUrl={data?.icon_url}
/>
<div className='system-xl-semibold text-text-secondary'>{data?.title}</div>
<div className='system-xs-regular text-text-tertiary'>
<div className="system-xl-semibold text-text-secondary">{data?.title}</div>
<div className="system-xs-regular text-text-tertiary">
{/* copyright */}
{data?.copyright && (
<div>© {(new Date()).getFullYear()} {data?.copyright}</div>
<div>
©
{(new Date()).getFullYear()}
{' '}
{data?.copyright}
</div>
)}
{data?.custom_disclaimer && (
<div className='mt-2'>{data.custom_disclaimer}</div>
<div className="mt-2">{data.custom_disclaimer}</div>
)}
</div>
</div>

View File

@ -1,14 +1,13 @@
'use client'
import type { FC } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import type { Placement } from '@floating-ui/react'
import type { FC } from 'react'
import type { SiteInfo } from '@/models/share'
import {
RiEqualizer2Line,
} from '@remixicon/react'
import { usePathname, useRouter } from 'next/navigation'
import Divider from '../../base/divider'
import InfoModal from './info-modal'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import ActionButton from '@/app/components/base/action-button'
import {
PortalToFollowElem,
@ -16,11 +15,12 @@ import {
PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem'
import ThemeSwitcher from '@/app/components/base/theme-switcher'
import type { SiteInfo } from '@/models/share'
import { cn } from '@/utils/classnames'
import { AccessMode } from '@/models/access-control'
import { useWebAppStore } from '@/context/web-app-context'
import { AccessMode } from '@/models/access-control'
import { webAppLogout } from '@/service/webapp-auth'
import { cn } from '@/utils/classnames'
import Divider from '../../base/divider'
import InfoModal from './info-modal'
type Props = {
data?: SiteInfo
@ -76,24 +76,24 @@ const MenuDropdown: FC<Props> = ({
>
<PortalToFollowElemTrigger onClick={handleTrigger}>
<div>
<ActionButton size='l' className={cn(open && 'bg-state-base-hover')}>
<RiEqualizer2Line className='h-[18px] w-[18px]' />
<ActionButton size="l" className={cn(open && 'bg-state-base-hover')}>
<RiEqualizer2Line className="h-[18px] w-[18px]" />
</ActionButton>
</div>
</PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-50'>
<div className='w-[224px] rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg backdrop-blur-sm'>
<div className='p-1'>
<PortalToFollowElemContent className="z-50">
<div className="w-[224px] rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg backdrop-blur-sm">
<div className="p-1">
<div className={cn('system-md-regular flex cursor-pointer items-center rounded-lg py-1.5 pl-3 pr-2 text-text-secondary')}>
<div className='grow'>{t('common.theme.theme')}</div>
<div className="grow">{t('common.theme.theme')}</div>
<ThemeSwitcher />
</div>
</div>
<Divider type='horizontal' className='my-0' />
<div className='p-1'>
<Divider type="horizontal" className="my-0" />
<div className="p-1">
{data?.privacy_policy && (
<a href={data.privacy_policy} target='_blank' className='system-md-regular flex cursor-pointer items-center rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover'>
<span className='grow'>{t('share.chat.privacyPolicyMiddle')}</span>
<a href={data.privacy_policy} target="_blank" className="system-md-regular flex cursor-pointer items-center rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover">
<span className="grow">{t('share.chat.privacyPolicyMiddle')}</span>
</a>
)}
<div
@ -101,14 +101,16 @@ const MenuDropdown: FC<Props> = ({
handleTrigger()
setShow(true)
}}
className='system-md-regular cursor-pointer rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover'
>{t('common.userProfile.about')}</div>
className="system-md-regular cursor-pointer rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover"
>
{t('common.userProfile.about')}
</div>
</div>
{!(hideLogout || webAppAccessMode === AccessMode.EXTERNAL_MEMBERS || webAppAccessMode === AccessMode.PUBLIC) && (
<div className='p-1'>
<div className="p-1">
<div
onClick={handleLogout}
className='system-md-regular cursor-pointer rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover'
className="system-md-regular cursor-pointer rounded-lg px-3 py-1.5 text-text-secondary hover:bg-state-base-hover"
>
{t('common.userProfile.logout')}
</div>

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import React from 'react'
import NoData from './index'
describe('NoData', () => {

View File

@ -1,18 +1,18 @@
import type { FC } from 'react'
import React from 'react'
import {
RiSparklingFill,
} from '@remixicon/react'
import React from 'react'
import { useTranslation } from 'react-i18next'
export type INoDataProps = {}
const NoData: FC<INoDataProps> = () => {
const { t } = useTranslation()
return (
<div className='flex h-full w-full flex-col items-center justify-center'>
<RiSparklingFill className='h-12 w-12 text-text-empty-state-icon' />
<div className="flex h-full w-full flex-col items-center justify-center">
<RiSparklingFill className="h-12 w-12 text-text-empty-state-icon" />
<div
className='system-sm-regular mt-2 text-text-quaternary'
className="system-sm-regular mt-2 text-text-quaternary"
>
{t('share.generation.noData')}
</div>

View File

@ -1,8 +1,8 @@
import type { FC } from 'react'
import React from 'react'
import Header from './header'
import type { FeedbackType } from '@/app/components/base/chat/chat/type'
import React from 'react'
import { format } from '@/service/base'
import Header from './header'
export type IResultProps = {
content: string
@ -17,17 +17,18 @@ const Result: FC<IResultProps> = ({
onFeedback,
}) => {
return (
<div className='h-max basis-3/4'>
<div className="h-max basis-3/4">
<Header result={content} showFeedback={showFeedback} feedback={feedback} onFeedback={onFeedback} />
<div
className='mt-4 flex w-full overflow-scroll text-sm font-normal leading-5 text-gray-900'
className="mt-4 flex w-full overflow-scroll text-sm font-normal leading-5 text-gray-900"
style={{
maxHeight: '70vh',
}}
dangerouslySetInnerHTML={{
__html: format(content),
}}
></div>
>
</div>
</div>
)
}

View File

@ -1,10 +1,10 @@
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import type { FeedbackType } from '@/app/components/base/chat/chat/type'
import { ClipboardDocumentIcon, HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline'
import copy from 'copy-to-clipboard'
import type { FeedbackType } from '@/app/components/base/chat/chat/type'
import React from 'react'
import { useTranslation } from 'react-i18next'
import Button from '@/app/components/base/button'
import Toast from '@/app/components/base/toast'
import Tooltip from '@/app/components/base/tooltip'
@ -24,19 +24,19 @@ const Header: FC<IResultHeaderProps> = ({
}) => {
const { t } = useTranslation()
return (
<div className='flex w-full items-center justify-between '>
<div className='text-2xl font-normal leading-4 text-gray-800'>{t('share.generation.resultTitle')}</div>
<div className='flex items-center space-x-2'>
<div className="flex w-full items-center justify-between ">
<div className="text-2xl font-normal leading-4 text-gray-800">{t('share.generation.resultTitle')}</div>
<div className="flex items-center space-x-2">
<Button
className='h-7 p-[2px] pr-2'
className="h-7 p-[2px] pr-2"
onClick={() => {
copy(result)
Toast.notify({ type: 'success', message: 'copied' })
}}
>
<>
<ClipboardDocumentIcon className='mr-1 h-3 w-4 text-gray-500' />
<span className='text-xs leading-3 text-gray-500'>{t('share.generation.copy')}</span>
<ClipboardDocumentIcon className="mr-1 h-3 w-4 text-gray-500" />
<span className="text-xs leading-3 text-gray-500">{t('share.generation.copy')}</span>
</>
</Button>
@ -50,7 +50,8 @@ const Header: FC<IResultHeaderProps> = ({
rating: null,
})
}}
className='flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border border-primary-200 bg-primary-100 !text-primary-600 hover:border-primary-300 hover:bg-primary-200'>
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border border-primary-200 bg-primary-100 !text-primary-600 hover:border-primary-300 hover:bg-primary-200"
>
<HandThumbUpIcon width={16} height={16} />
</div>
</Tooltip>
@ -66,14 +67,15 @@ const Header: FC<IResultHeaderProps> = ({
rating: null,
})
}}
className='flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border border-red-200 bg-red-100 !text-red-600 hover:border-red-300 hover:bg-red-200'>
className="flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border border-red-200 bg-red-100 !text-red-600 hover:border-red-300 hover:bg-red-200"
>
<HandThumbDownIcon width={16} height={16} />
</div>
</Tooltip>
)}
{showFeedback && !feedback.rating && (
<div className='flex space-x-1 rounded-lg border border-gray-200 p-[1px]'>
<div className="flex space-x-1 rounded-lg border border-gray-200 p-[1px]">
<Tooltip
popupContent="Great Rating"
needsDelay={false}
@ -84,7 +86,8 @@ const Header: FC<IResultHeaderProps> = ({
rating: 'like',
})
}}
className='flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-gray-100'>
className="flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-gray-100"
>
<HandThumbUpIcon width={16} height={16} />
</div>
</Tooltip>
@ -98,7 +101,8 @@ const Header: FC<IResultHeaderProps> = ({
rating: 'dislike',
})
}}
className='flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-gray-100'>
className="flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-gray-100"
>
<HandThumbDownIcon width={16} height={16} />
</div>
</Tooltip>

View File

@ -1,31 +1,32 @@
'use client'
import type { FC } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import type { FeedbackType } from '@/app/components/base/chat/chat/type'
import type { WorkflowProcess } from '@/app/components/base/chat/types'
import type { FileEntity } from '@/app/components/base/file-uploader/types'
import type { PromptConfig } from '@/models/debug'
import type { InstalledApp } from '@/models/explore'
import type { SiteInfo } from '@/models/share'
import type { VisionFile, VisionSettings } from '@/types/app'
import { RiLoader2Line } from '@remixicon/react'
import { useBoolean } from 'ahooks'
import { t } from 'i18next'
import { produce } from 'immer'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import TextGenerationRes from '@/app/components/app/text-generate/item'
import NoData from '@/app/components/share/text-generation/no-data'
import Toast from '@/app/components/base/toast'
import Button from '@/app/components/base/button'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import { RiLoader2Line } from '@remixicon/react'
import { sendCompletionMessage, sendWorkflowMessage, stopChatMessageResponding, stopWorkflowMessage, updateFeedback } from '@/service/share'
import type { FeedbackType } from '@/app/components/base/chat/chat/type'
import Loading from '@/app/components/base/loading'
import type { PromptConfig } from '@/models/debug'
import type { InstalledApp } from '@/models/explore'
import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app'
import { NodeRunningStatus, WorkflowRunningStatus } from '@/app/components/workflow/types'
import type { WorkflowProcess } from '@/app/components/base/chat/types'
import { sleep } from '@/utils'
import type { SiteInfo } from '@/models/share'
import { TEXT_GENERATION_TIMEOUT_MS } from '@/config'
import {
getFilesInLogs,
getProcessedFiles,
} from '@/app/components/base/file-uploader/utils'
import type { FileEntity } from '@/app/components/base/file-uploader/types'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import Loading from '@/app/components/base/loading'
import Toast from '@/app/components/base/toast'
import NoData from '@/app/components/share/text-generation/no-data'
import { NodeRunningStatus, WorkflowRunningStatus } from '@/app/components/workflow/types'
import { TEXT_GENERATION_TIMEOUT_MS } from '@/config'
import { sendCompletionMessage, sendWorkflowMessage, stopChatMessageResponding, stopWorkflowMessage, updateFeedback } from '@/service/share'
import { TransferMethod } from '@/types/app'
import { sleep } from '@/utils'
import { formatBooleanInputs } from '@/utils/model-config'
export type IResultProps = {
@ -52,7 +53,7 @@ export type IResultProps = {
completionFiles: VisionFile[]
siteInfo: SiteInfo | null
onRunStart: () => void
onRunControlChange?: (control: { onStop: () => Promise<void> | void; isStopping: boolean } | null) => void
onRunControlChange?: (control: { onStop: () => Promise<void> | void, isStopping: boolean } | null) => void
hideInlineStopButton?: boolean
}
@ -189,7 +190,7 @@ const Result: FC<IResultProps> = ({
let hasEmptyInput = ''
const requiredVars = prompt_variables?.filter(({ key, name, required, type }) => {
if(type === 'boolean' || type === 'checkbox')
if (type === 'boolean' || type === 'checkbox')
return false // boolean/checkbox input is not required
const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
return res
@ -534,16 +535,16 @@ const Result: FC<IResultProps> = ({
{!hideInlineStopButton && isResponding && currentTaskId && (
<div className={`mb-3 flex ${isPC ? 'justify-end' : 'justify-center'}`}>
<Button
variant='secondary'
variant="secondary"
disabled={isStopping}
onClick={handleStop}
>
{
isStopping
? <RiLoader2Line className='mr-[5px] h-3.5 w-3.5 animate-spin' />
: <StopCircle className='mr-[5px] h-3.5 w-3.5' />
? <RiLoader2Line className="mr-[5px] h-3.5 w-3.5 animate-spin" />
: <StopCircle className="mr-[5px] h-3.5 w-3.5" />
}
<span className='text-xs font-normal'>{t('appDebug.operation.stopResponding')}</span>
<span className="text-xs font-normal">{t('appDebug.operation.stopResponding')}</span>
</Button>
</div>
)}
@ -577,28 +578,28 @@ const Result: FC<IResultProps> = ({
{!isCallBatchAPI && !isWorkflow && (
(isResponding && !completionRes)
? (
<div className='flex h-full w-full items-center justify-center'>
<Loading type='area' />
</div>)
<div className="flex h-full w-full items-center justify-center">
<Loading type="area" />
</div>
)
: (
<>
{(isNoData)
? <NoData />
: renderTextGenerationRes()
}
</>
)
<>
{(isNoData)
? <NoData />
: renderTextGenerationRes()}
</>
)
)}
{!isCallBatchAPI && isWorkflow && (
(isResponding && !workflowProcessData)
? (
<div className='flex h-full w-full items-center justify-center'>
<Loading type='area' />
</div>
)
<div className="flex h-full w-full items-center justify-center">
<Loading type="area" />
</div>
)
: !workflowProcessData
? <NoData />
: renderTextGenerationRes()
? <NoData />
: renderTextGenerationRes()
)}
{isCallBatchAPI && renderTextGenerationRes()}
</>

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import React from 'react'
import CSVDownload from './index'
const mockType = { Link: 'mock-link' }
@ -26,7 +26,7 @@ describe('CSVDownload', () => {
vi.clearAllMocks()
})
test('should render table headers and sample row for each variable', () => {
it('should render table headers and sample row for each variable', () => {
render(<CSVDownload vars={vars} />)
expect(screen.getByText('share.generation.csvStructureTitle')).toBeInTheDocument()
@ -35,7 +35,7 @@ describe('CSVDownload', () => {
expect(screen.getByText('context share.generation.field')).toBeInTheDocument()
})
test('should configure CSV downloader with template data', () => {
it('should configure CSV downloader with template data', () => {
render(<CSVDownload vars={vars} />)
expect(capturedProps?.filename).toBe('template')

View File

@ -1,10 +1,10 @@
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import {
useCSVDownloader,
} from 'react-papaparse'
import { useTranslation } from 'react-i18next'
import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general'
export type ICSVDownloadProps = {
@ -26,21 +26,25 @@ const CSVDownload: FC<ICSVDownloadProps> = ({
})()
return (
<div className='mt-6'>
<div className='system-sm-medium text-text-primary'>{t('share.generation.csvStructureTitle')}</div>
<div className='mt-2 max-h-[500px] overflow-auto'>
<table className='w-full table-fixed border-separate border-spacing-0 rounded-lg border border-divider-regular text-xs'>
<thead className='text-text-tertiary'>
<div className="mt-6">
<div className="system-sm-medium text-text-primary">{t('share.generation.csvStructureTitle')}</div>
<div className="mt-2 max-h-[500px] overflow-auto">
<table className="w-full table-fixed border-separate border-spacing-0 rounded-lg border border-divider-regular text-xs">
<thead className="text-text-tertiary">
<tr>
{addQueryContentVars.map((item, i) => (
<td key={i} className='h-9 border-b border-divider-regular pl-3 pr-2'>{item.name}</td>
<td key={i} className="h-9 border-b border-divider-regular pl-3 pr-2">{item.name}</td>
))}
</tr>
</thead>
<tbody className='text-text-secondary'>
<tbody className="text-text-secondary">
<tr>
{addQueryContentVars.map((item, i) => (
<td key={i} className='h-9 pl-4'>{item.name} {t('share.generation.field')}</td>
<td key={i} className="h-9 pl-4">
{item.name}
{' '}
{t('share.generation.field')}
</td>
))}
</tr>
</tbody>
@ -49,7 +53,7 @@ const CSVDownload: FC<ICSVDownloadProps> = ({
<CSVDownloader
className="mt-2 block cursor-pointer"
type={Type.Link}
filename={'template'}
filename="template"
bom={true}
config={{
// delimiter: ';',
@ -58,8 +62,8 @@ const CSVDownload: FC<ICSVDownloadProps> = ({
template,
]}
>
<div className='system-xs-medium flex h-[18px] items-center space-x-1 text-text-accent'>
<DownloadIcon className='h-3 w-3' />
<div className="system-xs-medium flex h-[18px] items-center space-x-1 text-text-accent">
<DownloadIcon className="h-3 w-3" />
<span>{t('share.generation.downloadTemplate')}</span>
</div>
</CSVDownloader>

View File

@ -1,5 +1,5 @@
import React from 'react'
import { act, render, screen, waitFor } from '@testing-library/react'
import React from 'react'
import CSVReader from './index'
let mockAcceptedFile: { name: string } | null = null
@ -28,7 +28,7 @@ describe('CSVReader', () => {
vi.clearAllMocks()
})
test('should display upload instructions when no file selected', async () => {
it('should display upload instructions when no file selected', async () => {
const onParsed = vi.fn()
render(<CSVReader onParsed={onParsed} />)
@ -41,7 +41,7 @@ describe('CSVReader', () => {
expect(onParsed).toHaveBeenCalledWith([['row1']])
})
test('should show accepted file name without extension', () => {
it('should show accepted file name without extension', () => {
mockAcceptedFile = { name: 'batch.csv' }
render(<CSVReader onParsed={vi.fn()} />)
@ -49,7 +49,7 @@ describe('CSVReader', () => {
expect(screen.getByText('.csv')).toBeInTheDocument()
})
test('should toggle hover styling on drag events', async () => {
it('should toggle hover styling on drag events', async () => {
render(<CSVReader onParsed={vi.fn()} />)
const dragEvent = { preventDefault: vi.fn() } as unknown as DragEvent

View File

@ -1,12 +1,12 @@
'use client'
import type { FC } from 'react'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
useCSVReader,
} from 'react-papaparse'
import { useTranslation } from 'react-i18next'
import { cn } from '@/utils/classnames'
import { Csv as CSVIcon } from '@/app/components/base/icons/src/public/files'
import { cn } from '@/utils/classnames'
export type Props = {
onParsed: (data: string[][]) => void
@ -49,20 +49,24 @@ const CSVReader: FC<Props> = ({
{
acceptedFile
? (
<div className='flex w-full items-center space-x-2'>
<CSVIcon className="shrink-0" />
<div className='flex w-0 grow'>
<span className='max-w-[calc(100%_-_30px)] truncate text-text-secondary'>{acceptedFile.name.replace(/.csv$/, '')}</span>
<span className='shrink-0 text-text-tertiary'>.csv</span>
<div className="flex w-full items-center space-x-2">
<CSVIcon className="shrink-0" />
<div className="flex w-0 grow">
<span className="max-w-[calc(100%_-_30px)] truncate text-text-secondary">{acceptedFile.name.replace(/.csv$/, '')}</span>
<span className="shrink-0 text-text-tertiary">.csv</span>
</div>
</div>
</div>
)
)
: (
<div className='flex w-full items-center justify-center space-x-2'>
<CSVIcon className="shrink-0" />
<div className='text-text-tertiary'>{t('share.generation.csvUploadTitle')}<span className='cursor-pointer text-text-accent'>{t('share.generation.browse')}</span></div>
</div>
)}
<div className="flex w-full items-center justify-center space-x-2">
<CSVIcon className="shrink-0" />
<div className="text-text-tertiary">
{t('share.generation.csvUploadTitle')}
<span className="cursor-pointer text-text-accent">{t('share.generation.browse')}</span>
</div>
</div>
)
}
</div>
</>
)}

View File

@ -1,8 +1,8 @@
import type { Mock } from 'vitest'
import React from 'react'
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
import RunBatch from './index'
import React from 'react'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import RunBatch from './index'
vi.mock('@/hooks/use-breakpoints', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/hooks/use-breakpoints')>()
@ -42,7 +42,7 @@ describe('RunBatch', () => {
vi.clearAllMocks()
})
test('should enable run button after CSV parsed and send data', async () => {
it('should enable run button after CSV parsed and send data', async () => {
const onSend = vi.fn()
render(
<RunBatch
@ -66,7 +66,7 @@ describe('RunBatch', () => {
expect(onSend).toHaveBeenCalledWith([['row1']])
})
test('should keep button disabled and show spinner when results still running on mobile', async () => {
it('should keep button disabled and show spinner when results still running on mobile', async () => {
mockUseBreakpoints.mockReturnValue(MediaType.mobile)
const onSend = vi.fn()
const { container } = render(

View File

@ -1,16 +1,17 @@
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import {
RiLoader2Line,
RiPlayLargeLine,
} from '@remixicon/react'
import CSVReader from './csv-reader'
import CSVDownload from './csv-download'
import React from 'react'
import { useTranslation } from 'react-i18next'
import Button from '@/app/components/base/button'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import { cn } from '@/utils/classnames'
import CSVDownload from './csv-download'
import CSVReader from './csv-reader'
export type IRunBatchProps = {
vars: { name: string }[]
onSend: (data: string[][]) => void
@ -39,10 +40,10 @@ const RunBatch: FC<IRunBatchProps> = ({
}
const Icon = isAllFinished ? RiPlayLargeLine : RiLoader2Line
return (
<div className='pt-4'>
<div className="pt-4">
<CSVReader onParsed={handleParsed} />
<CSVDownload vars={vars} />
<div className='flex justify-end'>
<div className="flex justify-end">
<Button
variant="primary"
className={cn('mt-4 pl-3 pr-4', !isPC && 'grow')}
@ -50,7 +51,7 @@ const RunBatch: FC<IRunBatchProps> = ({
disabled={!isParsed || !isAllFinished}
>
<Icon className={cn(!isAllFinished && 'animate-spin', 'mr-1 h-4 w-4 shrink-0')} aria-hidden="true" />
<span className='text-[13px] uppercase'>{t('share.generation.run')}</span>
<span className="text-[13px] uppercase">{t('share.generation.run')}</span>
</Button>
</div>
</div>

View File

@ -1,5 +1,5 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import React from 'react'
import ResDownload from './index'
const mockType = { Link: 'mock-link' }

View File

@ -1,11 +1,11 @@
'use client'
import type { FC } from 'react'
import React from 'react'
import { RiDownloadLine } from '@remixicon/react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import {
useCSVDownloader,
} from 'react-papaparse'
import { useTranslation } from 'react-i18next'
import ActionButton from '@/app/components/base/action-button'
import Button from '@/app/components/base/button'
import { cn } from '@/utils/classnames'
@ -26,7 +26,7 @@ const ResDownload: FC<IResDownloadProps> = ({
<CSVDownloader
className="block cursor-pointer"
type={Type.Link}
filename={'result'}
filename="result"
bom={true}
config={{
// delimiter: ';',
@ -35,12 +35,12 @@ const ResDownload: FC<IResDownloadProps> = ({
>
{isMobile && (
<ActionButton>
<RiDownloadLine className='h-4 w-4' />
<RiDownloadLine className="h-4 w-4" />
</ActionButton>
)}
{!isMobile && (
<Button className={cn('space-x-1')}>
<RiDownloadLine className='h-4 w-4' />
<RiDownloadLine className="h-4 w-4" />
<span>{t('common.operation.download')}</span>
</Button>
)}

View File

@ -1,10 +1,10 @@
import React, { useEffect, useRef, useState } from 'react'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import RunOnce from './index'
import type { PromptConfig, PromptVariable } from '@/models/debug'
import type { SiteInfo } from '@/models/share'
import type { VisionSettings } from '@/types/app'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import React, { useEffect, useRef, useState } from 'react'
import { Resolution, TransferMethod } from '@/types/app'
import RunOnce from './index'
vi.mock('@/hooks/use-breakpoints', () => {
const MediaType = {
@ -22,7 +22,7 @@ vi.mock('@/hooks/use-breakpoints', () => {
vi.mock('@/app/components/workflow/nodes/_base/components/editor/code-editor', () => ({
__esModule: true,
default: ({ value, onChange }: { value?: string; onChange?: (val: string) => void }) => (
default: ({ value, onChange }: { value?: string, onChange?: (val: string) => void }) => (
<textarea data-testid="code-editor-mock" value={value} onChange={e => onChange?.(e.target.value)} />
),
}))

View File

@ -1,27 +1,26 @@
import type { ChangeEvent, FC, FormEvent } from 'react'
import { useEffect, useState } from 'react'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import type { PromptConfig } from '@/models/debug'
import type { SiteInfo } from '@/models/share'
import type { VisionFile, VisionSettings } from '@/types/app'
import {
RiLoader2Line,
RiPlayLargeLine,
} from '@remixicon/react'
import Select from '@/app/components/base/select'
import type { SiteInfo } from '@/models/share'
import type { PromptConfig } from '@/models/debug'
import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import Button from '@/app/components/base/button'
import Textarea from '@/app/components/base/textarea'
import Input from '@/app/components/base/input'
import { DEFAULT_VALUE_MAX_LEN } from '@/config'
import TextGenerationImageUploader from '@/app/components/base/image-uploader/text-generation-image-uploader'
import type { VisionFile, VisionSettings } from '@/types/app'
import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import { cn } from '@/utils/classnames'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import TextGenerationImageUploader from '@/app/components/base/image-uploader/text-generation-image-uploader'
import Input from '@/app/components/base/input'
import Select from '@/app/components/base/select'
import Textarea from '@/app/components/base/textarea'
import BoolInput from '@/app/components/workflow/nodes/_base/components/before-run-form/bool-input'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import { DEFAULT_VALUE_MAX_LEN } from '@/config'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import { cn } from '@/utils/classnames'
export type IRunOnceProps = {
siteInfo: SiteInfo
@ -86,7 +85,8 @@ const RunOnce: FC<IRunOnceProps> = ({
}, [onInputsChange, inputsRef])
useEffect(() => {
if (isInitialized) return
if (isInitialized)
return
const newInputs: Record<string, any> = {}
promptConfig.prompt_variables.forEach((item) => {
if (item.type === 'select')
@ -113,98 +113,99 @@ const RunOnce: FC<IRunOnceProps> = ({
<section>
{/* input form */}
<form onSubmit={onSubmit}>
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized ? null
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized
? null
: promptConfig.prompt_variables.filter(item => item.hide !== true).map(item => (
<div className='mt-4 w-full' key={item.key}>
{item.type !== 'checkbox' && (
<div className='system-md-semibold flex h-6 items-center gap-1 text-text-secondary'>
<div className='truncate'>{item.name}</div>
{!item.required && <span className='system-xs-regular text-text-tertiary'>{t('workflow.panel.optional')}</span>}
<div className="mt-4 w-full" key={item.key}>
{item.type !== 'checkbox' && (
<div className="system-md-semibold flex h-6 items-center gap-1 text-text-secondary">
<div className="truncate">{item.name}</div>
{!item.required && <span className="system-xs-regular text-text-tertiary">{t('workflow.panel.optional')}</span>}
</div>
)}
<div className="mt-1">
{item.type === 'select' && (
<Select
className="w-full"
defaultValue={inputs[item.key]}
onSelect={(i) => { handleInputsChange({ ...inputsRef.current, [item.key]: i.value }) }}
items={(item.options || []).map(i => ({ name: i, value: i }))}
allowSearch={false}
/>
)}
{item.type === 'string' && (
<Input
type="text"
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
/>
)}
{item.type === 'paragraph' && (
<Textarea
className="h-[104px] sm:text-xs"
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
/>
)}
{item.type === 'number' && (
<Input
type="number"
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
/>
)}
{item.type === 'checkbox' && (
<BoolInput
name={item.name || item.key}
value={!!inputs[item.key]}
required={item.required}
onChange={(value) => { handleInputsChange({ ...inputsRef.current, [item.key]: value }) }}
/>
)}
{item.type === 'file' && (
<FileUploaderInAttachmentWrapper
value={(inputs[item.key] && typeof inputs[item.key] === 'object') ? [inputs[item.key]] : []}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: files[0] }) }}
fileConfig={{
...item.config,
fileUploadConfig: (visionConfig as any).fileUploadConfig,
}}
/>
)}
{item.type === 'file-list' && (
<FileUploaderInAttachmentWrapper
value={Array.isArray(inputs[item.key]) ? inputs[item.key] : []}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: files }) }}
fileConfig={{
...item.config,
fileUploadConfig: (visionConfig as any).fileUploadConfig,
}}
/>
)}
{item.type === 'json_object' && (
<CodeEditor
language={CodeLanguage.json}
value={inputs[item.key]}
onChange={(value) => { handleInputsChange({ ...inputsRef.current, [item.key]: value }) }}
noWrapper
className="bg h-[80px] overflow-y-auto rounded-[10px] bg-components-input-bg-normal p-1"
placeholder={
<div className="whitespace-pre">{item.json_schema}</div>
}
/>
)}
</div>
)}
<div className='mt-1'>
{item.type === 'select' && (
<Select
className='w-full'
defaultValue={inputs[item.key]}
onSelect={(i) => { handleInputsChange({ ...inputsRef.current, [item.key]: i.value }) }}
items={(item.options || []).map(i => ({ name: i, value: i }))}
allowSearch={false}
/>
)}
{item.type === 'string' && (
<Input
type="text"
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
/>
)}
{item.type === 'paragraph' && (
<Textarea
className='h-[104px] sm:text-xs'
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
/>
)}
{item.type === 'number' && (
<Input
type="number"
placeholder={item.name}
value={inputs[item.key]}
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
/>
)}
{item.type === 'checkbox' && (
<BoolInput
name={item.name || item.key}
value={!!inputs[item.key]}
required={item.required}
onChange={(value) => { handleInputsChange({ ...inputsRef.current, [item.key]: value }) }}
/>
)}
{item.type === 'file' && (
<FileUploaderInAttachmentWrapper
value={(inputs[item.key] && typeof inputs[item.key] === 'object') ? [inputs[item.key]] : []}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: files[0] }) }}
fileConfig={{
...item.config,
fileUploadConfig: (visionConfig as any).fileUploadConfig,
}}
/>
)}
{item.type === 'file-list' && (
<FileUploaderInAttachmentWrapper
value={Array.isArray(inputs[item.key]) ? inputs[item.key] : []}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: files }) }}
fileConfig={{
...item.config,
fileUploadConfig: (visionConfig as any).fileUploadConfig,
}}
/>
)}
{item.type === 'json_object' && (
<CodeEditor
language={CodeLanguage.json}
value={inputs[item.key]}
onChange={(value) => { handleInputsChange({ ...inputsRef.current, [item.key]: value }) }}
noWrapper
className='bg h-[80px] overflow-y-auto rounded-[10px] bg-components-input-bg-normal p-1'
placeholder={
<div className='whitespace-pre'>{item.json_schema}</div>
}
/>
)}
</div>
</div>
))}
))}
{
visionConfig?.enabled && (
<div className="mt-4 w-full">
<div className="system-md-semibold flex h-6 items-center text-text-secondary">{t('common.imageUploader.imageUpload')}</div>
<div className='mt-1'>
<div className="mt-1">
<TextGenerationImageUploader
settings={visionConfig}
onFilesChange={files => onVisionFilesChange(files.filter(file => file.progress !== -1).map(fileItem => ({
@ -218,13 +219,13 @@ const RunOnce: FC<IRunOnceProps> = ({
</div>
)
}
<div className='mb-3 mt-6 w-full'>
<div className="mb-3 mt-6 w-full">
<div className="flex items-center justify-between gap-2">
<Button
onClick={onClear}
disabled={false}
>
<span className='text-[13px]'>{t('common.operation.clear')}</span>
<span className="text-[13px]">{t('common.operation.clear')}</span>
</Button>
<Button
className={cn(!isPC && 'grow')}
@ -234,20 +235,21 @@ const RunOnce: FC<IRunOnceProps> = ({
onClick={handlePrimaryClick}
data-testid={isRunning ? 'stop-button' : 'run-button'}
>
{isRunning ? (
<>
{runControl?.isStopping
? <RiLoader2Line className='mr-1 h-4 w-4 shrink-0 animate-spin' aria-hidden="true" />
: <StopCircle className='mr-1 h-4 w-4 shrink-0' aria-hidden="true" />
}
<span className='text-[13px]'>{stopLabel}</span>
</>
) : (
<>
<RiPlayLargeLine className="mr-1 h-4 w-4 shrink-0" aria-hidden="true" />
<span className='text-[13px]'>{t('share.generation.run')}</span>
</>
)}
{isRunning
? (
<>
{runControl?.isStopping
? <RiLoader2Line className="mr-1 h-4 w-4 shrink-0 animate-spin" aria-hidden="true" />
: <StopCircle className="mr-1 h-4 w-4 shrink-0" aria-hidden="true" />}
<span className="text-[13px]">{stopLabel}</span>
</>
)
: (
<>
<RiPlayLargeLine className="mr-1 h-4 w-4 shrink-0" aria-hidden="true" />
<span className="text-[13px]">{t('share.generation.run')}</span>
</>
)}
</Button>
</div>
</div>