tool selector support scope

pull/12372/head
JzoNg 1 year ago
parent 605085bddf
commit 23bf0a6812

@ -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,10 @@ const PluginDetailPanel: FC<Props> = ({
onUpdate() onUpdate()
} }
const testChange = (val: any) => {
console.log('tool change', val)
}
if (!detail) if (!detail)
return null return null
@ -52,6 +57,12 @@ 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} />}
<div>
<ToolSelector
value={undefined}
onSelect={item => testChange(item)}
/>
</div>
</div> </div>
</> </>
)} )}

@ -43,13 +43,15 @@ type Props = {
tool_name: string tool_name: string
}) => 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)
@ -73,6 +75,8 @@ const ToolSelector: FC<Props> = ({
const toolValue = { const toolValue = {
provider: tool.provider_id, provider: tool.provider_id,
tool_name: tool.tool_name, tool_name: tool.tool_name,
description: '',
parameters: {},
} }
onSelect(toolValue) onSelect(toolValue)
setIsShowChooseTool(false) setIsShowChooseTool(false)
@ -132,6 +136,7 @@ const ToolSelector: FC<Props> = ({
disabled={false} disabled={false}
supportAddCustomTool supportAddCustomTool
onSelect={handleSelectTool} onSelect={handleSelectTool}
scope={scope}
/> />
</div> </div>
{/* authorization panel */} {/* authorization panel */}

@ -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}

Loading…
Cancel
Save