import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { useAppContext } from '@/context/app-context' import Button from '@/app/components/base/button' import Toast from '@/app/components/base/toast' import Indicator from '@/app/components/header/indicator' import ToolItem from '@/app/components/tools/provider/tool-item' import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials' import { useAllToolProviders, useBuiltinTools, useInvalidateAllToolProviders, useRemoveProviderCredentials, useUpdateProviderCredentials, } from '@/service/use-tools' import type { PluginDetail } from '@/app/components/plugins/types' type Props = { detail: PluginDetail } const ActionList = ({ detail, }: Props) => { const { t } = useTranslation() const { isCurrentWorkspaceManager } = useAppContext() const providerBriefInfo = detail.declaration.tool.identity const providerKey = `${detail.plugin_id}/${providerBriefInfo.name}` const { data: collectionList = [] } = useAllToolProviders() const invalidateAllToolProviders = useInvalidateAllToolProviders() const provider = useMemo(() => { return collectionList.find(collection => collection.name === providerKey) }, [collectionList, providerKey]) const { data } = useBuiltinTools(providerKey) const [showSettingAuth, setShowSettingAuth] = useState(false) const handleCredentialSettingUpdate = () => { invalidateAllToolProviders() Toast.notify({ type: 'success', message: t('common.api.actionSuccess'), }) setShowSettingAuth(false) } const { mutate: updatePermission, isPending } = useUpdateProviderCredentials({ onSuccess: handleCredentialSettingUpdate, }) const { mutate: removePermission } = useRemoveProviderCredentials({ onSuccess: handleCredentialSettingUpdate, }) if (!data || !provider) return null return (
{t('plugin.detailPanel.actionNum', { num: data.length, action: data.length > 1 ? 'actions' : 'action' })} {provider.is_team_authorization && provider.allow_delete && ( )}
{!provider.is_team_authorization && provider.allow_delete && ( )}
{data.map(tool => ( ))}
{showSettingAuth && ( setShowSettingAuth(false)} onSaved={async value => updatePermission({ providerName: provider.name, credentials: value, })} onRemove={async () => removePermission(provider.name)} isSaving={isPending} /> )}
) } export default ActionList