import type { FC, FormEvent } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import { PlayIcon, } from '@heroicons/react/24/solid' import Select from '@/app/components/base/select' import type { SiteInfo } from '@/models/share' import type { PromptConfig } from '@/models/debug' import Button from '@/app/components/base/button' import Textarea from '@/app/components/base/textarea' 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 { getProcessedFiles } from '@/app/components/base/file-uploader/utils' export type IRunOnceProps = { siteInfo: SiteInfo promptConfig: PromptConfig inputs: Record onInputsChange: (inputs: Record) => void onSend: () => void visionConfig: VisionSettings onVisionFilesChange: (files: VisionFile[]) => void } const RunOnce: FC = ({ promptConfig, inputs, onInputsChange, onSend, visionConfig, onVisionFilesChange, }) => { const { t } = useTranslation() const onClear = () => { const newInputs: Record = {} promptConfig.prompt_variables.forEach((item) => { newInputs[item.key] = '' }) onInputsChange(newInputs) } const onSubmit = (e: FormEvent) => { e.preventDefault() onSend() } return (
{/* input form */}
{promptConfig.prompt_variables.map(item => (
{item.type === 'select' && ( { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN} /> )} {item.type === 'paragraph' && (