소스 검색

fix: can add a custom tool without a name (#6172)

tags/0.6.14
非法操作 1 년 전
부모
커밋
27d72e30ad
No account linked to committer's email address
2개의 변경된 파일41개의 추가작업 그리고 21개의 파일을 삭제
  1. 18
    2
      web/app/components/tools/edit-custom-collection-modal/index.tsx
  2. 23
    19
      web/app/components/tools/workflow-tool/index.tsx

+ 18
- 2
web/app/components/tools/edit-custom-collection-modal/index.tsx 파일 보기

import AppIcon from '@/app/components/base/app-icon' import AppIcon from '@/app/components/base/app-icon'
import { parseParamsSchema } from '@/service/tools' import { parseParamsSchema } from '@/service/tools'
import LabelSelector from '@/app/components/tools/labels/selector' import LabelSelector from '@/app/components/tools/labels/selector'
import Toast from '@/app/components/base/toast'


const fieldNameClassNames = 'py-2 leading-5 text-sm font-medium text-gray-900' const fieldNameClassNames = 'py-2 leading-5 text-sm font-medium text-gray-900'
type Props = { type Props = {
draft.labels = labels draft.labels = labels
}) })


let errorMessage = ''
if (!postData.provider)
errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.name') })

if (!postData.schema)
errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.schema') })

if (errorMessage) {
Toast.notify({
type: 'error',
message: errorMessage,
})
return
}

if (isAdd) { if (isAdd) {
onAdd?.(postData) onAdd?.(postData)
return return
<div className='flex flex-col h-full'> <div className='flex flex-col h-full'>
<div className='grow h-0 overflow-y-auto px-6 py-3 space-y-4'> <div className='grow h-0 overflow-y-auto px-6 py-3 space-y-4'>
<div> <div>
<div className={fieldNameClassNames}>{t('tools.createTool.name')}</div>
<div className={fieldNameClassNames}>{t('tools.createTool.name')} <span className='ml-1 text-red-500'>*</span></div>
<div className='flex items-center justify-between gap-3'> <div className='flex items-center justify-between gap-3'>
<AppIcon size='large' onClick={() => { setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} /> <AppIcon size='large' onClick={() => { setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} />
<input <input
<div className='select-none'> <div className='select-none'>
<div className='flex justify-between items-center'> <div className='flex justify-between items-center'>
<div className='flex items-center'> <div className='flex items-center'>
<div className={fieldNameClassNames}>{t('tools.createTool.schema')}</div>
<div className={fieldNameClassNames}>{t('tools.createTool.schema')}<span className='ml-1 text-red-500'>*</span></div>
<div className='mx-2 w-px h-3 bg-black/5'></div> <div className='mx-2 w-px h-3 bg-black/5'></div>
<a <a
href="https://swagger.io/specification/" href="https://swagger.io/specification/"

+ 23
- 19
web/app/components/tools/workflow-tool/index.tsx 파일 보기

const [showModal, setShowModal] = useState(false) const [showModal, setShowModal] = useState(false)


const isNameValid = (name: string) => { const isNameValid = (name: string) => {
// when the user has not input anything, no need for a warning
if (name === '')
return true

return /^[a-zA-Z0-9_]+$/.test(name) return /^[a-zA-Z0-9_]+$/.test(name)
} }


const onConfirm = () => { const onConfirm = () => {
if (!label) {
return Toast.notify({
type: 'error',
message: 'Please enter the tool name',
})
}
if (!name) {
return Toast.notify({
type: 'error',
message: 'Please enter the name for tool call',
})
}
else if (!isNameValid(name)) {
return Toast.notify({
let errorMessage = ''
if (!label)
errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.name') })

if (!name)
errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.nameForToolCall') })

if (!isNameValid(name))
errorMessage = t('tools.createTool.nameForToolCall') + t('tools.createTool.nameForToolCallTip')

if (errorMessage) {
Toast.notify({
type: 'error', type: 'error',
message: 'Name for tool call can only contain numbers, letters, and underscores',
message: errorMessage,
}) })
return
} }

const requestParams = { const requestParams = {
name, name,
description, description,
<div className='grow h-0 overflow-y-auto px-6 py-3 space-y-4'> <div className='grow h-0 overflow-y-auto px-6 py-3 space-y-4'>
{/* name & icon */} {/* name & icon */}
<div> <div>
<div className='py-2 leading-5 text-sm font-medium text-gray-900'>{t('tools.createTool.name')}</div>
<div className='py-2 leading-5 text-sm font-medium text-gray-900'>{t('tools.createTool.name')} <span className='ml-1 text-red-500'>*</span></div>
<div className='flex items-center justify-between gap-3'> <div className='flex items-center justify-between gap-3'>
<AppIcon size='large' onClick={() => { setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} /> <AppIcon size='large' onClick={() => { setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} />
<input <input
{/* name for tool call */} {/* name for tool call */}
<div> <div>
<div className='flex items-center py-2 leading-5 text-sm font-medium text-gray-900'> <div className='flex items-center py-2 leading-5 text-sm font-medium text-gray-900'>
{t('tools.createTool.nameForToolCall')}
{t('tools.createTool.nameForToolCall')} <span className='ml-1 text-red-500'>*</span>
<Tooltip <Tooltip
htmlContent={ htmlContent={
<div className='w-[180px]'> <div className='w-[180px]'>
onChange={e => setName(e.target.value)} onChange={e => setName(e.target.value)}
/> />
{!isNameValid(name) && ( {!isNameValid(name) && (
<div className='text-xs leading-[18px] text-[#DC6803]'>{t('tools.createTool.nameForToolCallTip')}</div>
<div className='text-xs leading-[18px] text-red-500'>{t('tools.createTool.nameForToolCallTip')}</div>
)} )}
</div> </div>
{/* description */} {/* description */}
)} )}
<div className='flex space-x-2 '> <div className='flex space-x-2 '>
<Button onClick={onHide}>{t('common.operation.cancel')}</Button> <Button onClick={onHide}>{t('common.operation.cancel')}</Button>
<Button disabled={!label || !name || !isNameValid(name)} variant='primary' onClick={() => {
<Button variant='primary' onClick={() => {
if (isAdd) if (isAdd)
onConfirm() onConfirm()
else else

Loading…
취소
저장