|
|
|
|
@ -3,6 +3,7 @@ import type { FC } from 'react'
|
|
|
|
|
import React, { useMemo, useState } from 'react'
|
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
import {
|
|
|
|
|
RiArrowLeftLine,
|
|
|
|
|
RiArrowRightUpLine,
|
|
|
|
|
} from '@remixicon/react'
|
|
|
|
|
import {
|
|
|
|
|
@ -39,7 +40,7 @@ import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
value?: {
|
|
|
|
|
provider: string
|
|
|
|
|
provider_name: string
|
|
|
|
|
tool_name: string
|
|
|
|
|
parameters?: Record<string, any>
|
|
|
|
|
extra?: Record<string, any>
|
|
|
|
|
@ -48,7 +49,7 @@ type Props = {
|
|
|
|
|
placement?: Placement
|
|
|
|
|
offset?: OffsetOptions
|
|
|
|
|
onSelect: (tool: {
|
|
|
|
|
provider: string
|
|
|
|
|
provider_name: string
|
|
|
|
|
tool_name: string
|
|
|
|
|
parameters?: Record<string, any>
|
|
|
|
|
extra?: Record<string, any>
|
|
|
|
|
@ -79,7 +80,7 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
const currentProvider = useMemo(() => {
|
|
|
|
|
const mergedTools = [...(buildInTools || []), ...(customTools || []), ...(workflowTools || [])]
|
|
|
|
|
return mergedTools.find((toolWithProvider) => {
|
|
|
|
|
return toolWithProvider.id === value?.provider && toolWithProvider.tools.some(tool => tool.name === value?.tool_name)
|
|
|
|
|
return toolWithProvider.id === value?.provider_name && toolWithProvider.tools.some(tool => tool.name === value?.tool_name)
|
|
|
|
|
})
|
|
|
|
|
}, [value, buildInTools, customTools, workflowTools])
|
|
|
|
|
|
|
|
|
|
@ -87,10 +88,12 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
const handleSelectTool = (tool: ToolDefaultValue) => {
|
|
|
|
|
const paramValues = addDefaultValue(tool.params, toolParametersToFormSchemas(tool.paramSchemas as any))
|
|
|
|
|
const toolValue = {
|
|
|
|
|
provider: tool.provider_id,
|
|
|
|
|
provider_name: tool.provider_id,
|
|
|
|
|
tool_name: tool.tool_name,
|
|
|
|
|
description: '',
|
|
|
|
|
parameters: paramValues,
|
|
|
|
|
extra: {
|
|
|
|
|
description: '',
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
onSelect(toolValue)
|
|
|
|
|
setIsShowChooseTool(false)
|
|
|
|
|
@ -160,7 +163,9 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
/>
|
|
|
|
|
</PortalToFollowElemTrigger>
|
|
|
|
|
<PortalToFollowElemContent className='z-[1000]'>
|
|
|
|
|
<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={cn('relative w-[361px] min-h-20 max-h-[642px] pb-4 rounded-xl backdrop-blur-sm bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg', !isShowSettingAuth && 'overflow-y-auto pb-2')}>
|
|
|
|
|
{!isShowSettingAuth && (
|
|
|
|
|
<>
|
|
|
|
|
<div className='px-4 pt-3.5 pb-1 text-text-primary system-xl-semibold'>{t('plugin.detailPanel.toolSelector.title')}</div>
|
|
|
|
|
{/* base form */}
|
|
|
|
|
<div className='px-4 py-2 flex flex-col gap-3'>
|
|
|
|
|
@ -191,11 +196,12 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
placeholder={t('plugin.detailPanel.toolSelector.descriptionPlaceholder')}
|
|
|
|
|
value={value?.extra?.description || ''}
|
|
|
|
|
onChange={handleDescriptionChange}
|
|
|
|
|
disabled={!value?.provider_name}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/* authorization */}
|
|
|
|
|
{!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.allow_delete && (
|
|
|
|
|
{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>
|
|
|
|
|
@ -226,19 +232,6 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* authorization panel */}
|
|
|
|
|
{isShowSettingAuth && currentProvider && (
|
|
|
|
|
<div className='px-4 pb-4 border-t border-divider-subtle'>
|
|
|
|
|
<ToolCredentialForm
|
|
|
|
|
collection={currentProvider}
|
|
|
|
|
onCancel={() => setShowSettingAuth(false)}
|
|
|
|
|
onSaved={async value => updatePermission({
|
|
|
|
|
providerName: currentProvider.name,
|
|
|
|
|
credentials: value,
|
|
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* tool settings */}
|
|
|
|
|
{currentToolParams.length > 0 && currentProvider?.is_team_authorization && (
|
|
|
|
|
<div className='px-4 pt-3'>
|
|
|
|
|
@ -269,6 +262,33 @@ const ToolSelector: FC<Props> = ({
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{/* authorization panel */}
|
|
|
|
|
{isShowSettingAuth && currentProvider && (
|
|
|
|
|
<>
|
|
|
|
|
<div className='relative pt-3.5 flex flex-col gap-1'>
|
|
|
|
|
<div className='absolute -top-2 left-2 w-[345px] pt-2 rounded-t-xl backdrop-blur-sm bg-components-panel-bg-blur border-[0.5px] border-components-panel-border'></div>
|
|
|
|
|
<div
|
|
|
|
|
className='px-3 h-6 flex items-center gap-1 text-text-accent-secondary system-xs-semibold-uppercase cursor-pointer'
|
|
|
|
|
onClick={() => setShowSettingAuth(false)}
|
|
|
|
|
>
|
|
|
|
|
<RiArrowLeftLine className='w-4 h-4' />
|
|
|
|
|
BACK
|
|
|
|
|
</div>
|
|
|
|
|
<div className='px-4 text-text-primary system-xl-semibold'>{t('tools.auth.setupModalTitle')}</div>
|
|
|
|
|
<div className='px-4 text-text-tertiary system-xs-regular'>{t('tools.auth.setupModalTitleDescription')}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<ToolCredentialForm
|
|
|
|
|
collection={currentProvider}
|
|
|
|
|
onCancel={() => setShowSettingAuth(false)}
|
|
|
|
|
onSaved={async value => updatePermission({
|
|
|
|
|
providerName: currentProvider.name,
|
|
|
|
|
credentials: value,
|
|
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</PortalToFollowElemContent>
|
|
|
|
|
</PortalToFollowElem>
|
|
|
|
|
|