mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 16:32:01 +08:00
Merge branch 'feat/plugins' of https://github.com/langgenius/dify into feat/plugins
This commit is contained in:
commit
b4e9dddbca
@ -275,7 +275,10 @@ function Form<
|
|||||||
|
|
||||||
if (formSchema.type === FormTypeEnum.toolSelector) {
|
if (formSchema.type === FormTypeEnum.toolSelector) {
|
||||||
const {
|
const {
|
||||||
variable, label, required,
|
variable,
|
||||||
|
label,
|
||||||
|
required,
|
||||||
|
scope,
|
||||||
} = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)
|
} = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -288,6 +291,7 @@ function Form<
|
|||||||
{tooltipContent}
|
{tooltipContent}
|
||||||
</div>
|
</div>
|
||||||
<ToolSelector
|
<ToolSelector
|
||||||
|
scope={scope}
|
||||||
disabled={readonly}
|
disabled={readonly}
|
||||||
value={value[variable]}
|
value={value[variable]}
|
||||||
onSelect={item => handleFormChange(variable, item as any)} />
|
onSelect={item => handleFormChange(variable, item as any)} />
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import ActionList from './action-list'
|
|||||||
import ModelList from './model-list'
|
import ModelList from './model-list'
|
||||||
import AgentStrategyList from './agent-strategy-list'
|
import AgentStrategyList from './agent-strategy-list'
|
||||||
import Drawer from '@/app/components/base/drawer'
|
import Drawer from '@/app/components/base/drawer'
|
||||||
|
import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector'
|
||||||
import type { PluginDetail } from '@/app/components/plugins/types'
|
import type { PluginDetail } from '@/app/components/plugins/types'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
@ -27,6 +28,12 @@ const PluginDetailPanel: FC<Props> = ({
|
|||||||
onUpdate()
|
onUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [value, setValue] = React.useState<any>(undefined)
|
||||||
|
const testChange = (val: any) => {
|
||||||
|
console.log('tool change', val)
|
||||||
|
setValue(val)
|
||||||
|
}
|
||||||
|
|
||||||
if (!detail)
|
if (!detail)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@ -52,6 +59,14 @@ const PluginDetailPanel: FC<Props> = ({
|
|||||||
{!!detail.declaration.agent_strategy && <AgentStrategyList detail={detail} />}
|
{!!detail.declaration.agent_strategy && <AgentStrategyList detail={detail} />}
|
||||||
{!!detail.declaration.endpoint && <EndpointList detail={detail} />}
|
{!!detail.declaration.endpoint && <EndpointList detail={detail} />}
|
||||||
{!!detail.declaration.model && <ModelList detail={detail} />}
|
{!!detail.declaration.model && <ModelList detail={detail} />}
|
||||||
|
{false && (
|
||||||
|
<div className='px-4 py-2'>
|
||||||
|
<ToolSelector
|
||||||
|
value={value}
|
||||||
|
onSelect={item => testChange(item)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useMemo, useState } from 'react'
|
import React, { useMemo, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
RiArrowRightUpLine,
|
||||||
|
} from '@remixicon/react'
|
||||||
import {
|
import {
|
||||||
PortalToFollowElem,
|
PortalToFollowElem,
|
||||||
PortalToFollowElemContent,
|
PortalToFollowElemContent,
|
||||||
@ -13,6 +16,10 @@ import Button from '@/app/components/base/button'
|
|||||||
import Indicator from '@/app/components/header/indicator'
|
import Indicator from '@/app/components/header/indicator'
|
||||||
import ToolCredentialForm from '@/app/components/plugins/plugin-detail-panel/tool-selector/tool-credentials-form'
|
import ToolCredentialForm from '@/app/components/plugins/plugin-detail-panel/tool-selector/tool-credentials-form'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
|
import Textarea from '@/app/components/base/textarea'
|
||||||
|
import Divider from '@/app/components/base/divider'
|
||||||
|
import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
|
||||||
|
import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
||||||
|
|
||||||
import { useAppContext } from '@/context/app-context'
|
import { useAppContext } from '@/context/app-context'
|
||||||
import {
|
import {
|
||||||
@ -34,6 +41,8 @@ type Props = {
|
|||||||
value?: {
|
value?: {
|
||||||
provider: string
|
provider: string
|
||||||
tool_name: string
|
tool_name: string
|
||||||
|
description?: string
|
||||||
|
parameters?: Record<string, any>
|
||||||
}
|
}
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
placement?: Placement
|
placement?: Placement
|
||||||
@ -41,15 +50,19 @@ type Props = {
|
|||||||
onSelect: (tool: {
|
onSelect: (tool: {
|
||||||
provider: string
|
provider: string
|
||||||
tool_name: string
|
tool_name: string
|
||||||
|
description?: string
|
||||||
|
parameters?: Record<string, any>
|
||||||
}) => void
|
}) => void
|
||||||
supportAddCustomTool?: boolean
|
supportAddCustomTool?: boolean
|
||||||
|
scope?: string
|
||||||
}
|
}
|
||||||
const ToolSelector: FC<Props> = ({
|
const ToolSelector: FC<Props> = ({
|
||||||
value,
|
value,
|
||||||
disabled,
|
disabled,
|
||||||
placement = 'bottom',
|
placement = 'left',
|
||||||
offset = 4,
|
offset = 4,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
scope,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [isShow, onShowChange] = useState(false)
|
const [isShow, onShowChange] = useState(false)
|
||||||
@ -62,23 +75,52 @@ const ToolSelector: FC<Props> = ({
|
|||||||
const { data: customTools } = useAllCustomTools()
|
const { data: customTools } = useAllCustomTools()
|
||||||
const { data: workflowTools } = useAllWorkflowTools()
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
const invalidateAllBuiltinTools = useInvalidateAllBuiltInTools()
|
const invalidateAllBuiltinTools = useInvalidateAllBuiltInTools()
|
||||||
|
|
||||||
const currentProvider = useMemo(() => {
|
const currentProvider = useMemo(() => {
|
||||||
const mergedTools = [...(buildInTools || []), ...(customTools || []), ...(workflowTools || [])]
|
const mergedTools = [...(buildInTools || []), ...(customTools || []), ...(workflowTools || [])]
|
||||||
return mergedTools.find((toolWithProvider) => {
|
return mergedTools.find((toolWithProvider) => {
|
||||||
return toolWithProvider.id === value?.provider && toolWithProvider.tools.some(tool => tool.name === value?.tool_name)
|
return toolWithProvider.id === value?.provider && toolWithProvider.tools.some(tool => tool.name === value?.tool_name)
|
||||||
})
|
})
|
||||||
}, [value, buildInTools, customTools, workflowTools])
|
}, [value, buildInTools, customTools, workflowTools])
|
||||||
|
|
||||||
const [isShowChooseTool, setIsShowChooseTool] = useState(false)
|
const [isShowChooseTool, setIsShowChooseTool] = useState(false)
|
||||||
const handleSelectTool = (tool: ToolDefaultValue) => {
|
const handleSelectTool = (tool: ToolDefaultValue) => {
|
||||||
|
const paramValues = addDefaultValue(tool.params, toolParametersToFormSchemas(tool.paramSchemas as any))
|
||||||
const toolValue = {
|
const toolValue = {
|
||||||
provider: tool.provider_id,
|
provider: tool.provider_id,
|
||||||
tool_name: tool.tool_name,
|
tool_name: tool.tool_name,
|
||||||
|
description: '',
|
||||||
|
parameters: paramValues,
|
||||||
}
|
}
|
||||||
onSelect(toolValue)
|
onSelect(toolValue)
|
||||||
setIsShowChooseTool(false)
|
setIsShowChooseTool(false)
|
||||||
if (tool.provider_type === CollectionType.builtIn && tool.is_team_authorization)
|
// if (tool.provider_type === CollectionType.builtIn && tool.is_team_authorization)
|
||||||
onShowChange(false)
|
// onShowChange(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDescriptionChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
onSelect({
|
||||||
|
...value,
|
||||||
|
description: e.target.value || '',
|
||||||
|
} as any)
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentToolParams = useMemo(() => {
|
||||||
|
if (!currentProvider) return []
|
||||||
|
return currentProvider.tools.find(tool => tool.name === value?.tool_name)?.parameters || []
|
||||||
|
}, [currentProvider, value])
|
||||||
|
|
||||||
|
const formSchemas = useMemo(() => toolParametersToFormSchemas(currentToolParams), [currentToolParams])
|
||||||
|
|
||||||
|
const handleFormChange = (v: Record<string, any>) => {
|
||||||
|
const toolValue = {
|
||||||
|
...value,
|
||||||
|
parameters: v,
|
||||||
|
}
|
||||||
|
onSelect(toolValue as any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// authorization
|
||||||
const { isCurrentWorkspaceManager } = useAppContext()
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const [isShowSettingAuth, setShowSettingAuth] = useState(false)
|
const [isShowSettingAuth, setShowSettingAuth] = useState(false)
|
||||||
const handleCredentialSettingUpdate = () => {
|
const handleCredentialSettingUpdate = () => {
|
||||||
@ -108,32 +150,79 @@ const ToolSelector: FC<Props> = ({
|
|||||||
onClick={handleTriggerClick}
|
onClick={handleTriggerClick}
|
||||||
>
|
>
|
||||||
<ToolTrigger
|
<ToolTrigger
|
||||||
|
isConfigure
|
||||||
open={isShow}
|
open={isShow}
|
||||||
value={value}
|
value={value}
|
||||||
provider={currentProvider}
|
provider={currentProvider}
|
||||||
/>
|
/>
|
||||||
</PortalToFollowElemTrigger>
|
</PortalToFollowElemTrigger>
|
||||||
<PortalToFollowElemContent className='z-[1000]'>
|
<PortalToFollowElemContent className='z-[1000]'>
|
||||||
<div className="relative w-[389px] min-h-20 rounded-xl bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg">
|
<div className="relative w-[361px] min-h-20 max-h-[642px] overflow-y-auto pb-2 rounded-xl backdrop-blur-sm bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg">
|
||||||
<div className='px-4 py-3 flex flex-col gap-1'>
|
<div className='px-4 pt-3.5 pb-1 text-text-primary system-xl-semibold'>{t('plugin.detailPanel.toolSelector.title')}</div>
|
||||||
<div className='h-6 flex items-center system-sm-semibold text-text-secondary'>{t('tools.toolSelector.label')}</div>
|
{/* base form */}
|
||||||
<ToolPicker
|
<div className='px-4 py-2 flex flex-col gap-3'>
|
||||||
placement='bottom'
|
<div className='flex flex-col gap-1'>
|
||||||
offset={offset}
|
<div className='h-6 flex items-center system-sm-semibold text-text-secondary'>{t('plugin.detailPanel.toolSelector.toolLabel')}</div>
|
||||||
trigger={
|
<ToolPicker
|
||||||
<ToolTrigger
|
placement='bottom'
|
||||||
open={isShowChooseTool}
|
offset={offset}
|
||||||
value={value}
|
trigger={
|
||||||
provider={currentProvider}
|
<ToolTrigger
|
||||||
/>
|
open={isShowChooseTool}
|
||||||
}
|
value={value}
|
||||||
isShow={isShowChooseTool}
|
provider={currentProvider}
|
||||||
onShowChange={setIsShowChooseTool}
|
/>
|
||||||
disabled={false}
|
}
|
||||||
supportAddCustomTool
|
isShow={isShowChooseTool}
|
||||||
onSelect={handleSelectTool}
|
onShowChange={setIsShowChooseTool}
|
||||||
/>
|
disabled={false}
|
||||||
|
supportAddCustomTool
|
||||||
|
onSelect={handleSelectTool}
|
||||||
|
scope={scope}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col gap-1'>
|
||||||
|
<div className='h-6 flex items-center system-sm-semibold text-text-secondary'>{t('plugin.detailPanel.toolSelector.descriptionLabel')}</div>
|
||||||
|
<Textarea
|
||||||
|
className='resize-none'
|
||||||
|
placeholder={t('plugin.detailPanel.toolSelector.descriptionPlaceholder')}
|
||||||
|
value={value?.description || ''}
|
||||||
|
onChange={handleDescriptionChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/* authorization */}
|
||||||
|
{!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.allow_delete && (
|
||||||
|
<div className='px-4 pt-3 flex flex-col'>
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<div className='text-text-tertiary system-xs-medium-uppercase'>{t('plugin.detailPanel.toolSelector.auth')}</div>
|
||||||
|
<Divider bgStyle='gradient' className='grow' />
|
||||||
|
</div>
|
||||||
|
<div className='py-2'>
|
||||||
|
{!currentProvider.is_team_authorization && (
|
||||||
|
<Button
|
||||||
|
variant='primary'
|
||||||
|
className={cn('shrink-0 w-full')}
|
||||||
|
onClick={() => setShowSettingAuth(true)}
|
||||||
|
disabled={!isCurrentWorkspaceManager}
|
||||||
|
>
|
||||||
|
{t('tools.auth.unauthorized')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{currentProvider.is_team_authorization && (
|
||||||
|
<Button
|
||||||
|
variant='secondary'
|
||||||
|
className={cn('shrink-0 w-full')}
|
||||||
|
onClick={() => setShowSettingAuth(true)}
|
||||||
|
disabled={!isCurrentWorkspaceManager}
|
||||||
|
>
|
||||||
|
<Indicator className='mr-2' color={'green'} />
|
||||||
|
{t('tools.auth.authorized')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{/* authorization panel */}
|
{/* authorization panel */}
|
||||||
{isShowSettingAuth && currentProvider && (
|
{isShowSettingAuth && currentProvider && (
|
||||||
<div className='px-4 pb-4 border-t border-divider-subtle'>
|
<div className='px-4 pb-4 border-t border-divider-subtle'>
|
||||||
@ -147,31 +236,34 @@ const ToolSelector: FC<Props> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.is_team_authorization && currentProvider.allow_delete && (
|
{/* tool settings */}
|
||||||
<div className='px-4 py-3 flex items-center border-t border-divider-subtle'>
|
{currentToolParams.length > 0 && currentProvider?.is_team_authorization && (
|
||||||
<div className='grow mr-3 h-6 flex items-center system-sm-semibold text-text-secondary'>{t('tools.toolSelector.auth')}</div>
|
<div className='px-4 pt-3'>
|
||||||
{isCurrentWorkspaceManager && (
|
<div className='flex items-center gap-2'>
|
||||||
<Button
|
<div className='text-text-tertiary system-xs-medium-uppercase'>{t('plugin.detailPanel.toolSelector.settings')}</div>
|
||||||
variant='secondary'
|
<Divider bgStyle='gradient' className='grow' />
|
||||||
size='small'
|
</div>
|
||||||
onClick={() => {}}
|
<div className='py-2'>
|
||||||
>
|
<Form
|
||||||
<Indicator className='mr-2' color={'green'} />
|
value={value?.parameters || {}}
|
||||||
{t('tools.auth.authorized')}
|
onChange={handleFormChange}
|
||||||
</Button>
|
formSchemas={formSchemas as any}
|
||||||
)}
|
isEditMode={true}
|
||||||
</div>
|
showOnVariableMap={{}}
|
||||||
)}
|
validating={false}
|
||||||
{!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && !currentProvider.is_team_authorization && currentProvider.allow_delete && (
|
inputClassName='bg-components-input-bg-normal hover:bg-components-input-bg-hover'
|
||||||
<div className='px-4 py-3 flex items-center border-t border-divider-subtle'>
|
fieldMoreInfo={item => item.url
|
||||||
<Button
|
? (<a
|
||||||
variant='primary'
|
href={item.url}
|
||||||
className={cn('shrink-0 w-full')}
|
target='_blank' rel='noopener noreferrer'
|
||||||
onClick={() => setShowSettingAuth(true)}
|
className='inline-flex items-center text-xs text-text-accent'
|
||||||
disabled={!isCurrentWorkspaceManager}
|
>
|
||||||
>
|
{t('tools.howToGet')}
|
||||||
{t('tools.auth.unauthorized')}
|
<RiArrowRightUpLine className='ml-1 w-3 h-3' />
|
||||||
</Button>
|
</a>)
|
||||||
|
: null}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import React from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import {
|
import {
|
||||||
RiArrowDownSLine,
|
RiArrowDownSLine,
|
||||||
|
RiEqualizer2Line,
|
||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import BlockIcon from '@/app/components/workflow/block-icon'
|
import BlockIcon from '@/app/components/workflow/block-icon'
|
||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
@ -16,21 +17,23 @@ type Props = {
|
|||||||
provider: string
|
provider: string
|
||||||
tool_name: string
|
tool_name: string
|
||||||
}
|
}
|
||||||
|
isConfigure?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolTrigger = ({
|
const ToolTrigger = ({
|
||||||
open,
|
open,
|
||||||
provider,
|
provider,
|
||||||
value,
|
value,
|
||||||
|
isConfigure,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
return (
|
return (
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
'group flex items-center p-2 pl-3 bg-components-input-bg-normal rounded-lg cursor-pointer hover:bg-state-base-hover-alt',
|
'group flex items-center p-2 pl-3 bg-components-input-bg-normal rounded-lg cursor-pointer hover:bg-state-base-hover-alt',
|
||||||
open && 'bg-state-base-hover-alt',
|
open && 'bg-state-base-hover-alt',
|
||||||
value && 'pl-1.5 py-1.5',
|
value?.provider && 'pl-1.5 py-1.5',
|
||||||
)}>
|
)}>
|
||||||
{value && provider && (
|
{value?.provider && provider && (
|
||||||
<div className='shrink-0 mr-1 p-px rounded-lg bg-components-panel-bg border border-components-panel-border'>
|
<div className='shrink-0 mr-1 p-px rounded-lg bg-components-panel-bg border border-components-panel-border'>
|
||||||
<BlockIcon
|
<BlockIcon
|
||||||
className='!w-4 !h-4'
|
className='!w-4 !h-4'
|
||||||
@ -39,13 +42,20 @@ const ToolTrigger = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{value && (
|
{value?.tool_name && (
|
||||||
<div className='grow system-sm-medium text-components-input-text-filled'>{value.tool_name}</div>
|
<div className='grow system-sm-medium text-components-input-text-filled'>{value.tool_name}</div>
|
||||||
)}
|
)}
|
||||||
{!value && (
|
{!value?.provider && (
|
||||||
<div className='grow text-components-input-text-placeholder system-sm-regular'>{t('tools.toolSelector.placeholder')}</div>
|
<div className='grow text-components-input-text-placeholder system-sm-regular'>
|
||||||
|
{!isConfigure ? t('plugin.detailPanel.toolSelector.placeholder') : t('plugin.detailPanel.configureTool')}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isConfigure && (
|
||||||
|
<RiEqualizer2Line className={cn('shrink-0 ml-0.5 w-4 h-4 text-text-quaternary group-hover:text-text-secondary', open && 'text-text-secondary')} />
|
||||||
|
)}
|
||||||
|
{!isConfigure && (
|
||||||
|
<RiArrowDownSLine className={cn('shrink-0 ml-0.5 w-4 h-4 text-text-quaternary group-hover:text-text-secondary', open && 'text-text-secondary')} />
|
||||||
)}
|
)}
|
||||||
<RiArrowDownSLine className={cn('shrink-0 ml-0.5 w-4 h-4 text-text-quaternary group-hover:text-text-secondary', open && 'text-text-secondary')} />
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useState } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
PortalToFollowElem,
|
PortalToFollowElem,
|
||||||
PortalToFollowElemContent,
|
PortalToFollowElemContent,
|
||||||
@ -34,6 +34,7 @@ type Props = {
|
|||||||
onShowChange: (isShow: boolean) => void
|
onShowChange: (isShow: boolean) => void
|
||||||
onSelect: (tool: ToolDefaultValue) => void
|
onSelect: (tool: ToolDefaultValue) => void
|
||||||
supportAddCustomTool?: boolean
|
supportAddCustomTool?: boolean
|
||||||
|
scope?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const ToolPicker: FC<Props> = ({
|
const ToolPicker: FC<Props> = ({
|
||||||
@ -45,6 +46,7 @@ const ToolPicker: FC<Props> = ({
|
|||||||
onShowChange,
|
onShowChange,
|
||||||
onSelect,
|
onSelect,
|
||||||
supportAddCustomTool,
|
supportAddCustomTool,
|
||||||
|
scope = 'all',
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [searchText, setSearchText] = useState('')
|
const [searchText, setSearchText] = useState('')
|
||||||
@ -55,6 +57,35 @@ const ToolPicker: FC<Props> = ({
|
|||||||
const invalidateCustomTools = useInvalidateAllCustomTools()
|
const invalidateCustomTools = useInvalidateAllCustomTools()
|
||||||
const { data: workflowTools } = useAllWorkflowTools()
|
const { data: workflowTools } = useAllWorkflowTools()
|
||||||
|
|
||||||
|
const { builtinToolList, customToolList, workflowToolList } = useMemo(() => {
|
||||||
|
if (scope === 'plugins') {
|
||||||
|
return {
|
||||||
|
builtinToolList: buildInTools,
|
||||||
|
customToolList: [],
|
||||||
|
workflowToolList: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scope === 'custom') {
|
||||||
|
return {
|
||||||
|
builtinToolList: [],
|
||||||
|
customToolList: customTools,
|
||||||
|
workflowToolList: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scope === 'workflow') {
|
||||||
|
return {
|
||||||
|
builtinToolList: [],
|
||||||
|
customToolList: [],
|
||||||
|
workflowToolList: workflowTools,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
builtinToolList: buildInTools,
|
||||||
|
customToolList: customTools,
|
||||||
|
workflowToolList: workflowTools,
|
||||||
|
}
|
||||||
|
}, [scope, buildInTools, customTools, workflowTools])
|
||||||
|
|
||||||
const handleAddedCustomTool = invalidateCustomTools
|
const handleAddedCustomTool = invalidateCustomTools
|
||||||
|
|
||||||
const handleTriggerClick = () => {
|
const handleTriggerClick = () => {
|
||||||
@ -122,9 +153,9 @@ const ToolPicker: FC<Props> = ({
|
|||||||
tags={tags}
|
tags={tags}
|
||||||
searchText={searchText}
|
searchText={searchText}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
buildInTools={buildInTools || []}
|
buildInTools={builtinToolList || []}
|
||||||
customTools={customTools || []}
|
customTools={customToolList || []}
|
||||||
workflowTools={workflowTools || []}
|
workflowTools={workflowToolList || []}
|
||||||
supportAddCustomTool={supportAddCustomTool}
|
supportAddCustomTool={supportAddCustomTool}
|
||||||
onAddedCustomTool={handleAddedCustomTool}
|
onAddedCustomTool={handleAddedCustomTool}
|
||||||
onShowAddCustomCollectionModal={showEditCustomCollectionModal}
|
onShowAddCustomCollectionModal={showEditCustomCollectionModal}
|
||||||
|
|||||||
@ -59,6 +59,7 @@ const ToolItem: FC<Props> = ({
|
|||||||
title: payload.label[language],
|
title: payload.label[language],
|
||||||
is_team_authorization: provider.is_team_authorization,
|
is_team_authorization: provider.is_team_authorization,
|
||||||
output_schema: payload.output_schema,
|
output_schema: payload.output_schema,
|
||||||
|
paramSchemas: payload.parameters,
|
||||||
params,
|
params,
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -27,5 +27,6 @@ export type ToolDefaultValue = {
|
|||||||
title: string
|
title: string
|
||||||
is_team_authorization: boolean
|
is_team_authorization: boolean
|
||||||
params: Record<string, any>
|
params: Record<string, any>
|
||||||
|
paramSchemas: Record<string, any>
|
||||||
output_schema: Record<string, any>
|
output_schema: Record<string, any>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import Form from '@/app/components/header/account-setting/model-provider-page/mo
|
|||||||
import { Agent } from '@/app/components/base/icons/src/vender/workflow'
|
import { Agent } from '@/app/components/base/icons/src/vender/workflow'
|
||||||
import { InputNumber } from '@/app/components/base/input-number'
|
import { InputNumber } from '@/app/components/base/input-number'
|
||||||
import Slider from '@/app/components/base/slider'
|
import Slider from '@/app/components/base/slider'
|
||||||
|
import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector'
|
||||||
import Field from './field'
|
import Field from './field'
|
||||||
import type { ComponentProps } from 'react'
|
import type { ComponentProps } from 'react'
|
||||||
|
|
||||||
@ -29,9 +30,10 @@ export type AgentStrategyProps = {
|
|||||||
type CustomSchema<Type, Field = {}> = Omit<CredentialFormSchema, 'type'> & { type: Type } & Field
|
type CustomSchema<Type, Field = {}> = Omit<CredentialFormSchema, 'type'> & { type: Type } & Field
|
||||||
|
|
||||||
type MaxIterFormSchema = CustomSchema<'max-iter'>
|
type MaxIterFormSchema = CustomSchema<'max-iter'>
|
||||||
type ToolSelectorSchema = CustomSchema<'array[tools]'>
|
type ToolSelectorSchema = CustomSchema<'tool-selector'>
|
||||||
|
type MultipleToolSelectorSchema = CustomSchema<'array[tools]'>
|
||||||
|
|
||||||
type CustomField = MaxIterFormSchema | ToolSelectorSchema
|
type CustomField = MaxIterFormSchema | ToolSelectorSchema | MultipleToolSelectorSchema
|
||||||
|
|
||||||
export const AgentStrategy = (props: AgentStrategyProps) => {
|
export const AgentStrategy = (props: AgentStrategyProps) => {
|
||||||
const { strategy, onStrategyChange, formSchema, formValue, onFormValueChange } = props
|
const { strategy, onStrategyChange, formSchema, formValue, onFormValueChange } = props
|
||||||
@ -61,9 +63,23 @@ export const AgentStrategy = (props: AgentStrategyProps) => {
|
|||||||
</div>
|
</div>
|
||||||
</Field>
|
</Field>
|
||||||
}
|
}
|
||||||
|
case 'tool-selector': {
|
||||||
|
const value = props.value[schema.variable]
|
||||||
|
const onChange = (value: any) => {
|
||||||
|
props.onChange({ ...props.value, [schema.variable]: value })
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Field title={'tool selector'} tooltip={'tool selector'}>
|
||||||
|
<ToolSelector
|
||||||
|
value={value}
|
||||||
|
onSelect={item => onChange(item)}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
)
|
||||||
|
}
|
||||||
case 'array[tools]': {
|
case 'array[tools]': {
|
||||||
return <Field title={'tool selector'} tooltip={'tool selector'}>
|
return <Field title={'tool selector'} tooltip={'tool selector'}>
|
||||||
tool selector
|
multiple tool selector TODO
|
||||||
</Field>
|
</Field>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import type { AgentNodeType } from './types'
|
|||||||
|
|
||||||
const nodeDefault: NodeDefault<AgentNodeType> = {
|
const nodeDefault: NodeDefault<AgentNodeType> = {
|
||||||
defaultValue: {
|
defaultValue: {
|
||||||
max_iterations: 3,
|
|
||||||
},
|
},
|
||||||
getAvailablePrevNodes(isChatMode) {
|
getAvailablePrevNodes(isChatMode) {
|
||||||
return isChatMode
|
return isChatMode
|
||||||
|
|||||||
@ -9,12 +9,6 @@ import { useTranslation } from 'react-i18next'
|
|||||||
const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
||||||
const { inputs, setInputs, currentStrategy } = useConfig(props.id, props.data)
|
const { inputs, setInputs, currentStrategy } = useConfig(props.id, props.data)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [iter, setIter] = [inputs.max_iterations, (value: number) => {
|
|
||||||
setInputs({
|
|
||||||
...inputs,
|
|
||||||
max_iterations: value,
|
|
||||||
})
|
|
||||||
}]
|
|
||||||
return <div className='space-y-2 my-2'>
|
return <div className='space-y-2 my-2'>
|
||||||
<Field title={t('workflow.nodes.agent.strategy.label')} className='px-4' >
|
<Field title={t('workflow.nodes.agent.strategy.label')} className='px-4' >
|
||||||
<AgentStrategy
|
<AgentStrategy
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import type { CommonNodeType } from '@/app/components/workflow/types'
|
|||||||
import type { ToolVarInputs } from '../tool/types'
|
import type { ToolVarInputs } from '../tool/types'
|
||||||
|
|
||||||
export type AgentNodeType = CommonNodeType & {
|
export type AgentNodeType = CommonNodeType & {
|
||||||
max_iterations: number
|
|
||||||
agent_strategy_provider_name?: string
|
agent_strategy_provider_name?: string
|
||||||
agent_strategy_name?: string
|
agent_strategy_name?: string
|
||||||
agent_strategy_label?: string
|
agent_strategy_label?: string
|
||||||
|
|||||||
@ -65,6 +65,18 @@ const translation = {
|
|||||||
serviceOk: 'Service OK',
|
serviceOk: 'Service OK',
|
||||||
disabled: 'Disabled',
|
disabled: 'Disabled',
|
||||||
modelNum: '{{num}} MODELS INCLUDED',
|
modelNum: '{{num}} MODELS INCLUDED',
|
||||||
|
toolSelector: {
|
||||||
|
title: 'Add tool',
|
||||||
|
toolLabel: 'Tool',
|
||||||
|
descriptionLabel: 'Tool description',
|
||||||
|
descriptionPlaceholder: 'Brief description of the tool\'s purpose, e.g., get the temperature for a specific location.',
|
||||||
|
placeholder: 'Select a tool...',
|
||||||
|
auth: 'AUTHORIZATION',
|
||||||
|
settings: 'TOOL SETTINGS',
|
||||||
|
},
|
||||||
|
configureApp: 'Configure App',
|
||||||
|
configureModel: 'Configure model',
|
||||||
|
configureTool: 'Configure tool',
|
||||||
},
|
},
|
||||||
install: '{{num}} installs',
|
install: '{{num}} installs',
|
||||||
installAction: 'Install',
|
installAction: 'Install',
|
||||||
|
|||||||
@ -152,11 +152,6 @@ const translation = {
|
|||||||
openInStudio: 'Open in Studio',
|
openInStudio: 'Open in Studio',
|
||||||
toolNameUsageTip: 'Tool call name for agent reasoning and prompting',
|
toolNameUsageTip: 'Tool call name for agent reasoning and prompting',
|
||||||
copyToolName: 'Copy Name',
|
copyToolName: 'Copy Name',
|
||||||
toolSelector: {
|
|
||||||
label: 'TOOL',
|
|
||||||
placeholder: 'Select a tool...',
|
|
||||||
auth: 'AUTHORIZATION',
|
|
||||||
},
|
|
||||||
noTools: 'No tools found',
|
noTools: 'No tools found',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,6 +65,18 @@ const translation = {
|
|||||||
serviceOk: '服务正常',
|
serviceOk: '服务正常',
|
||||||
disabled: '停用',
|
disabled: '停用',
|
||||||
modelNum: '{{num}} 模型已包含',
|
modelNum: '{{num}} 模型已包含',
|
||||||
|
toolSelector: {
|
||||||
|
title: '添加工具',
|
||||||
|
toolLabel: '工具',
|
||||||
|
descriptionLabel: '工具描述',
|
||||||
|
descriptionPlaceholder: '简要描述工具目的,例如,获取特定位置的温度。',
|
||||||
|
placeholder: '选择工具',
|
||||||
|
auth: '授权',
|
||||||
|
settings: '工具设置',
|
||||||
|
},
|
||||||
|
configureApp: '应用设置',
|
||||||
|
configureModel: '模型设置',
|
||||||
|
configureTool: '工具设置',
|
||||||
},
|
},
|
||||||
install: '{{num}} 次安装',
|
install: '{{num}} 次安装',
|
||||||
installAction: '安装',
|
installAction: '安装',
|
||||||
|
|||||||
@ -152,10 +152,6 @@ const translation = {
|
|||||||
openInStudio: '在工作室中打开',
|
openInStudio: '在工作室中打开',
|
||||||
toolNameUsageTip: '工具调用名称,用于 Agent 推理和提示词',
|
toolNameUsageTip: '工具调用名称,用于 Agent 推理和提示词',
|
||||||
copyToolName: '复制名称',
|
copyToolName: '复制名称',
|
||||||
toolSelector: {
|
|
||||||
label: '工具',
|
|
||||||
placeholder: '选择一个工具...',
|
|
||||||
},
|
|
||||||
noTools: '没有工具',
|
noTools: '没有工具',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user