'use client' import type { SandboxFileTreeNode } from '@/types/sandbox-file' import * as React from 'react' import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import FolderSpark from '@/app/components/base/icons/src/vender/workflow/FolderSpark' import { useStore, useWorkflowStore } from '@/app/components/workflow/store' import { useDownloadSandboxFile, useSandboxFilesTree } from '@/service/use-sandbox-file' import { cn } from '@/utils/classnames' import { downloadUrl } from '@/utils/download' import ArtifactsTree from './artifacts-tree' type ArtifactsSectionProps = { className?: string } const ArtifactsSection = ({ className }: ArtifactsSectionProps) => { const { t } = useTranslation('workflow') const appId = useStore(s => s.appId) const [isExpanded, setIsExpanded] = useState(false) const { data: treeData, hasFiles, isLoading } = useSandboxFilesTree(appId) const { mutateAsync: fetchDownloadUrl, isPending: isDownloading } = useDownloadSandboxFile(appId) const storeApi = useWorkflowStore() const selectedArtifactPath = useStore(s => s.selectedArtifactPath) const handleToggle = useCallback(() => { setIsExpanded(prev => !prev) }, []) const handleSelect = useCallback((node: SandboxFileTreeNode) => { storeApi.getState().selectArtifact(node.path) }, [storeApi]) const handleDownload = useCallback(async (node: SandboxFileTreeNode) => { try { const ticket = await fetchDownloadUrl(node.path) downloadUrl({ url: ticket.download_url, fileName: node.name }) } catch (error) { console.error('Download failed:', error) } }, [fetchDownloadUrl]) const showBlueDot = !isExpanded && hasFiles const showSpinner = isLoading return (
{isExpanded && !isLoading && (
{hasFiles ? ( ) : (

{t('skillSidebar.artifacts.emptyState')}

)}
)}
) } export default React.memo(ArtifactsSection)