'use client' import type { ReactNode } from 'react' import { useSuspenseQuery } from '@tanstack/react-query' import { noop } from 'es-toolkit/function' import { useMemo, useState } from 'react' import InstallFromLocalPackage from '@/app/components/plugins/install-plugin/install-from-local-package' import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context' import { PluginPageContextProvider } from '@/app/components/plugins/plugin-page/context-provider' import PluginsPanel from '@/app/components/plugins/plugin-page/plugins-panel' import { useUploader } from '@/app/components/plugins/plugin-page/use-uploader' import { PluginCategoryEnum } from '@/app/components/plugins/types' import { SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS } from '@/config' import { systemFeaturesQueryOptions } from '@/features/system-features/client' type PluginCategoryPageProps = { canInstall?: boolean category: PluginCategoryEnum layout?: (parts: { body: ReactNode, toolbar: ReactNode }) => ReactNode onSwitchToMarketplace?: () => void toolbarAction?: ReactNode } const supportedLocalPackageExtensions = SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS.split(',') const PluginCategoryPageContent = ({ canInstall = true, category, layout, onSwitchToMarketplace, toolbarAction, }: PluginCategoryPageProps) => { const [currentFile, setCurrentFile] = useState(null) const containerRef = usePluginPageContext(v => v.containerRef) const { data: pluginInstallationPermission } = useSuspenseQuery({ ...systemFeaturesQueryOptions(), select: s => s.plugin_installation_permission, }) const supportsDropInstall = category === PluginCategoryEnum.tool || category === PluginCategoryEnum.trigger || category === PluginCategoryEnum.agent || category === PluginCategoryEnum.extension const canDropLocalPackage = canInstall && supportsDropInstall && !pluginInstallationPermission.restrict_to_marketplace_only const handleFileChange = (file: File | null) => { if (!canInstall) { setCurrentFile(null) return } if (!file || !supportedLocalPackageExtensions.some(extension => file.name.endsWith(extension))) { setCurrentFile(null) return } setCurrentFile(file) } const { dragging, fileUploader, fileChangeHandle, removeFile, } = useUploader({ onFileChange: handleFileChange, containerRef, enabled: canDropLocalPackage, }) return (
{dragging && (
)} {currentFile && ( )}
) } const PluginCategoryPage = ({ canInstall = true, category, layout, onSwitchToMarketplace, toolbarAction, }: PluginCategoryPageProps) => { const initialFilters = useMemo(() => ({ categories: [category], tags: [], searchQuery: '', }), [category]) return ( ) } export default PluginCategoryPage