diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx index e6ce15d696..cef2146daa 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx @@ -18,6 +18,7 @@ import { SimpleSelect } from '@/app/components/base/select' import Tooltip from '@/app/components/base/tooltip' import Radio from '@/app/components/base/radio' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' +import ToolSelector from '@/app/components/tools/tool-selector' type FormProps = { className?: string @@ -317,7 +318,32 @@ const Form: FC = ({ } if (formSchema.type === FormTypeEnum.toolSelector) { - // TODO + const { + variable, + label, + required, + } = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput) + + return ( +
+
+ {label[language] || label.en_US} + { + required && ( + * + ) + } + {tooltipContent} +
+ handleFormChange(variable, item as any)} + /> + {fieldMoreInfo?.(formSchema)} + {validating && changeKey === variable && } +
+ ) } if (formSchema.type === FormTypeEnum.appSelector) { diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx index 342b66e948..ca4813d3c6 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React, { useState } from 'react' +import React from 'react' import { useTranslation } from 'react-i18next' import { RiArrowRightUpLine, RiCloseLine } from '@remixicon/react' import ActionButton from '@/app/components/base/action-button' @@ -11,8 +11,6 @@ import Toast from '@/app/components/base/toast' import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks' import cn from '@/utils/classnames' -import ToolSelector from '@/app/components/tools/tool-selector' - type Props = { formSchemas: any defaultValues?: any @@ -40,11 +38,6 @@ const EndpointModal: FC = ({ onSaved(tempCredential) } - const [mockTool, setTool] = useState({ - provider: 'langgenius/google/google', - tool_name: 'google_search', - }) - return ( = ({ ) : null} /> -
diff --git a/web/app/components/tools/tool-selector/index.tsx b/web/app/components/tools/tool-selector/index.tsx index 2689abbbc6..75b02698de 100644 --- a/web/app/components/tools/tool-selector/index.tsx +++ b/web/app/components/tools/tool-selector/index.tsx @@ -9,12 +9,18 @@ import { } from '@/app/components/base/portal-to-follow-elem' import ToolTrigger from '@/app/components/tools/tool-selector/tool-trigger' import ToolPicker from '@/app/components/workflow/block-selector/tool-picker' -import Loading from '@/app/components/base/loading' import Button from '@/app/components/base/button' import Indicator from '@/app/components/header/indicator' +import ToolCredentialForm from '@/app/components/tools/tool-selector/tool-credentials-form' +import Toast from '@/app/components/base/toast' import { useAppContext } from '@/context/app-context' -import { useAllBuiltInTools, useAllCustomTools, useAllWorkflowTools } from '@/service/use-tools' +import { + useAllBuiltInTools, + useAllCustomTools, + useAllWorkflowTools, + useUpdateProviderCredentials, +} from '@/service/use-tools' import { CollectionType } from '@/app/components/tools/types' import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types' import type { @@ -28,7 +34,7 @@ type Props = { provider: string tool_name: string } - disabled: boolean + disabled?: boolean placement?: Placement offset?: OffsetOptions onSelect: (tool: { @@ -72,18 +78,19 @@ const ToolSelector: FC = ({ onShowChange(false) } const { isCurrentWorkspaceManager } = useAppContext() - const [authLoading, setAuthLoading] = useState(false) + const [isShowSettingAuth, setShowSettingAuth] = useState(false) + const handleCredentialSettingUpdate = () => { + Toast.notify({ + type: 'success', + message: t('common.api.actionSuccess'), + }) + setShowSettingAuth(false) + onShowChange(false) + } - // const [isShowSettingAuth, setShowSettingAuth] = useState(false) - - // const handleToolAuthSetting = (value: any) => { - // const newModelConfig = produce(modelConfig, (draft) => { - // const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === value?.collection?.id && item.tool_name === value?.tool_name) - // if (tool) - // (tool as AgentTool).notAuthor = false - // }) - // setModelConfig(newModelConfig) - // } + const { mutate: updatePermission } = useUpdateProviderCredentials({ + onSuccess: handleCredentialSettingUpdate, + }) return ( <> @@ -125,10 +132,19 @@ const ToolSelector: FC = ({ />
{/* authorization panel */} - {authLoading && ( -
+ {isShowSettingAuth && currentProvider && ( +
+ setShowSettingAuth(false)} + onSaved={async value => updatePermission({ + providerName: currentProvider.name, + credentials: value, + })} + /> +
)} - {!authLoading && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.is_team_authorization && currentProvider.allow_delete && ( + {!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && currentProvider.is_team_authorization && currentProvider.allow_delete && (
{t('tools.toolSelector.auth')}
{isCurrentWorkspaceManager && ( @@ -143,12 +159,12 @@ const ToolSelector: FC = ({ )}
)} - {!authLoading && currentProvider && currentProvider.type === CollectionType.builtIn && !currentProvider.is_team_authorization && currentProvider.allow_delete && ( + {!isShowSettingAuth && currentProvider && currentProvider.type === CollectionType.builtIn && !currentProvider.is_team_authorization && currentProvider.allow_delete && (
+ +
+
+ + ) + } + + + ) +} +export default React.memo(ToolCredentialForm)