|
|
|
@ -25,7 +25,6 @@ import {
|
|
|
|
useInvalidateMCPTools,
|
|
|
|
useInvalidateMCPTools,
|
|
|
|
useMCPTools,
|
|
|
|
useMCPTools,
|
|
|
|
useUpdateMCP,
|
|
|
|
useUpdateMCP,
|
|
|
|
useUpdateMCPAuthorizationToken,
|
|
|
|
|
|
|
|
useUpdateMCPTools,
|
|
|
|
useUpdateMCPTools,
|
|
|
|
} from '@/service/use-tools'
|
|
|
|
} from '@/service/use-tools'
|
|
|
|
import { openOAuthPopup } from '@/hooks/use-oauth'
|
|
|
|
import { openOAuthPopup } from '@/hooks/use-oauth'
|
|
|
|
@ -53,7 +52,6 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
const invalidateMCPTools = useInvalidateMCPTools()
|
|
|
|
const invalidateMCPTools = useInvalidateMCPTools()
|
|
|
|
const { mutateAsync: updateTools, isPending: isUpdating } = useUpdateMCPTools()
|
|
|
|
const { mutateAsync: updateTools, isPending: isUpdating } = useUpdateMCPTools()
|
|
|
|
const { mutateAsync: authorizeMcp, isPending: isAuthorizing } = useAuthorizeMCP()
|
|
|
|
const { mutateAsync: authorizeMcp, isPending: isAuthorizing } = useAuthorizeMCP()
|
|
|
|
const { mutateAsync: updateMCPAuthorizationToken } = useUpdateMCPAuthorizationToken()
|
|
|
|
|
|
|
|
const toolList = data?.tools || []
|
|
|
|
const toolList = data?.tools || []
|
|
|
|
|
|
|
|
|
|
|
|
const handleUpdateTools = useCallback(async () => {
|
|
|
|
const handleUpdateTools = useCallback(async () => {
|
|
|
|
@ -62,7 +60,7 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
await updateTools(detail.id)
|
|
|
|
await updateTools(detail.id)
|
|
|
|
invalidateMCPTools(detail.id)
|
|
|
|
invalidateMCPTools(detail.id)
|
|
|
|
onUpdate()
|
|
|
|
onUpdate()
|
|
|
|
}, [detail, updateTools])
|
|
|
|
}, [detail, invalidateMCPTools, onUpdate, updateTools])
|
|
|
|
|
|
|
|
|
|
|
|
const { mutate: updateMCP } = useUpdateMCP({
|
|
|
|
const { mutate: updateMCP } = useUpdateMCP({
|
|
|
|
onSuccess: onUpdate,
|
|
|
|
onSuccess: onUpdate,
|
|
|
|
@ -86,17 +84,13 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
setFalse: hideDeleting,
|
|
|
|
setFalse: hideDeleting,
|
|
|
|
}] = useBoolean(false)
|
|
|
|
}] = useBoolean(false)
|
|
|
|
|
|
|
|
|
|
|
|
const handleOAuthCallback = async (state: string, code: string) => {
|
|
|
|
const handleOAuthCallback = useCallback((state: string) => {
|
|
|
|
if (!isCurrentWorkspaceManager)
|
|
|
|
if (!isCurrentWorkspaceManager)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
if (detail.id !== state)
|
|
|
|
if (detail.id !== state)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
await updateMCPAuthorizationToken({
|
|
|
|
|
|
|
|
provider_id: state,
|
|
|
|
|
|
|
|
authorization_code: code,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
handleUpdateTools()
|
|
|
|
handleUpdateTools()
|
|
|
|
}
|
|
|
|
}, [detail.id, handleUpdateTools, isCurrentWorkspaceManager])
|
|
|
|
|
|
|
|
|
|
|
|
const handleAuthorize = useCallback(async () => {
|
|
|
|
const handleAuthorize = useCallback(async () => {
|
|
|
|
onFirstCreate()
|
|
|
|
onFirstCreate()
|
|
|
|
@ -112,7 +106,7 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
|
|
|
|
|
|
|
|
else if (res.authorization_url)
|
|
|
|
else if (res.authorization_url)
|
|
|
|
openOAuthPopup(res.authorization_url, handleOAuthCallback)
|
|
|
|
openOAuthPopup(res.authorization_url, handleOAuthCallback)
|
|
|
|
}, [detail, updateMCP, hideUpdateModal, onUpdate])
|
|
|
|
}, [onFirstCreate, isCurrentWorkspaceManager, detail, authorizeMcp, handleUpdateTools, handleOAuthCallback])
|
|
|
|
|
|
|
|
|
|
|
|
const handleUpdate = useCallback(async (data: any) => {
|
|
|
|
const handleUpdate = useCallback(async (data: any) => {
|
|
|
|
if (!detail)
|
|
|
|
if (!detail)
|
|
|
|
@ -137,11 +131,12 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
hideDeleteConfirm()
|
|
|
|
hideDeleteConfirm()
|
|
|
|
onUpdate(true)
|
|
|
|
onUpdate(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [detail, showDeleting, hideDeleting, hideDeleteConfirm, onUpdate])
|
|
|
|
}, [detail, showDeleting, deleteMCP, hideDeleting, hideDeleteConfirm, onUpdate])
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (isCreation)
|
|
|
|
if (isCreation)
|
|
|
|
handleAuthorize()
|
|
|
|
handleAuthorize()
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [])
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
if (!detail)
|
|
|
|
if (!detail)
|
|
|
|
@ -175,6 +170,7 @@ const MCPDetailContent: FC<Props> = ({
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
variant='secondary'
|
|
|
|
variant='secondary'
|
|
|
|
className='w-full'
|
|
|
|
className='w-full'
|
|
|
|
|
|
|
|
onClick={handleAuthorize}
|
|
|
|
disabled={!isCurrentWorkspaceManager}
|
|
|
|
disabled={!isCurrentWorkspaceManager}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<Indicator className='mr-2' color={'green'} />
|
|
|
|
<Indicator className='mr-2' color={'green'} />
|
|
|
|
|