123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- 'use client'
- import type { FC } from 'react'
- import React, { useState } from 'react'
- import { useTranslation } from 'react-i18next'
- import produce from 'immer'
- import type { Emoji, WorkflowToolProviderParameter, WorkflowToolProviderRequest } from '../types'
- import cn from '@/utils/classnames'
- import Drawer from '@/app/components/base/drawer-plus'
- import Input from '@/app/components/base/input'
- import Textarea from '@/app/components/base/textarea'
- import Button from '@/app/components/base/button'
- import Toast from '@/app/components/base/toast'
- import EmojiPicker from '@/app/components/base/emoji-picker'
- import AppIcon from '@/app/components/base/app-icon'
- import MethodSelector from '@/app/components/tools/workflow-tool/method-selector'
- import LabelSelector from '@/app/components/tools/labels/selector'
- import ConfirmModal from '@/app/components/tools/workflow-tool/confirm-modal'
- import Tooltip from '@/app/components/base/tooltip'
- type Props = {
- isAdd?: boolean
- payload: any
- onHide: () => void
- onRemove?: () => void
- onCreate?: (payload: WorkflowToolProviderRequest & { workflow_app_id: string }) => void
- onSave?: (payload: WorkflowToolProviderRequest & Partial<{
- workflow_app_id: string
- workflow_tool_id: string
- }>) => void
- }
- const WorkflowToolAsModal: FC<Props> = ({
- isAdd,
- payload,
- onHide,
- onRemove,
- onSave,
- onCreate,
- }) => {
- const { t } = useTranslation()
- const [showEmojiPicker, setShowEmojiPicker] = useState<boolean>(false)
- const [emoji, setEmoji] = useState<Emoji>(payload.icon)
- const [label, setLabel] = useState<string>(payload.label)
- const [name, setName] = useState(payload.name)
- const [description, setDescription] = useState(payload.description)
- const [parameters, setParameters] = useState<WorkflowToolProviderParameter[]>(payload.parameters)
- const
- const
- if
- draft[index].description
- else
- draft[index].form
- })
- setParameters(newData)
- }
- const
- const
- setLabels(value)
- }
- const
- const
- const
-
- if
- return
- return /^[a-zA-Z0-9_]+$/
- }
- const
- let
- if
- errorMessage
- if
- errorMessage
- if
- errorMessage
- if
- Toast.notify({
- type: 'error',
- message: errorMessage,
- })
- return
- }
- const
- name,
- description,
- icon: emoji,
- label,
- parameters: parameters.map(item
- name: item.name,
- description: item.description,
- form: item.form,
- })),
- labels,
- privacy_policy: privacyPolicy,
- }
- if
- onSave?.({
- ...requestParams,
- workflow_tool_id: payload.workflow_tool_id,
- })
- }
- else
- onCreate?.({
- ...requestParams,
- workflow_app_id: payload.workflow_app_id,
- })
- }
- }
- return
- <>
- <Drawer
- isShow
- onHide={onHide}
- title={t('workflow.common.workflowAsTool')!}
- panelClassName='mt-2 !w-[640px]'
- maxWidthClassName='!max-w-[640px]'
- height='calc(100vh - 16px)'
- headerClassName='!border-b-divider'
- body={
- <div
- <div
- {}
- <div>
- <div /span></
- <div
- <AppIcon />
- <Input
- className=
- placeholder={t()!}
- value={label}
- onChange={e => setLabel(e.target.value)}
- /
- </div>
- </div>
- {}
- <div>
- <div
- {t('tools.createTool.nameForToolCall')} <span /span>
- <Tooltip
- popupContent={
- <div className=>
- {t()}
- </
- }
- />
- </div>
- <Input
- className='h-10'
- placeholder={t('tools.createTool.nameForToolCallPlaceHolder')!}
- value={name}
- onChange={e
- />
- {!isNameValid(name) && (
- <div className=>{t()}</div>
- )}
- </div>
- {}
- <div>
- <div className=>{t()}</div>
- <Textarea
- placeholder={t('tools.createTool.descriptionPlaceholder') || ''}
- value={description}
- onChange={e
- />
- </div>
- {}
- <div>
- <div /div>
- <div className=>
- <table className=>
- <thead className=>
- <tr className=>
- <th className=>{t()}</
- <th /th>
- <th className=>{t()}</
- </tr>
- </thead>
- <tbody>
- {parameters.map((item, index) => (
- <tr
- <td
- <div
- <div
- <span /span>
- <span className=>{item.required ? t() : }</
- </div>
- <div className=>{item.type}</div>
- </div>
- </td>
- <td>
- {item.name
- <div
- 'flex items-center gap-1 min-h-[56px] px-3 py-2 h-9 bg-transparent cursor-default',
- )}>
- <div
- {t('tools.createTool.toolInput.methodParameter')}
- </div>
- </div>
- )}
- {item.name
- <MethodSelector />
- )}
- </
- <td
- <input
- type='text'
- className='w-full text-text-secondary text-[13px] leading-[18px] font-normal bg-transparent outline-none appearance-none caret-primary-600 placeholder:text-text-quaternary'
- placeholder={t('tools.createTool.toolInput.descriptionPlaceholder')!}
- value={item.description}
- onChange={e
- />
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- </div>
- {}
- <div>
- <div className=>{t()}</div>
- <LabelSelector />
- </
- {}
- <div>
- <div /div>
- <Input
- className=
- value={privacyPolicy}
- onChange={e => setPrivacyPolicy(e.target.value)}
- placeholder={t() || } /
- </div>
- </div>
- <div
- {!isAdd
- <Button /Button>
- )}
- <div className=>
- <Button onClick={onHide}>{t()}</
- <Button
- if
- onConfirm()
- else
- setShowModal(true)
- }}>{t('common.operation.save')}</Button>
- </div>
- </div>
- </div>
- }
- isShowMask={true}
- clickOutsideNotOpen={true}
- />
- {showEmojiPicker && <EmojiPicker
- onSelect={(icon, icon_background) => {
- setEmoji({ content: icon, background: icon_background })
- setShowEmojiPicker(false)
- }}
- onClose={() => {
- setShowEmojiPicker(false)
- }}
- />}
- {showModal
- <ConfirmModal
- show={showModal}
- onClose={() => setShowModal(false)}
- onConfirm={onConfirm}
- />
- )}
- </>
- )
- }
- export
|