import { useEffect, useState } from 'react'; import { Download, Folder, Paperclip } from 'lucide-react'; import { usePendingCloudInput } from './CloudPending'; import { Button } from '@/components/ui/button'; import { cloudAgentsApi } from '@/lib/cloud-agents-api'; import type { CloudAttachment, CloudFile, CloudUpload } from '../../../shared/cloud-agents'; export function CloudFiles({ threadId, ensureThread, selected, onSelected, onBusy, disabled }: { threadId?: string; ensureThread: () => Promise; selected: string[]; onSelected: (ids: string[]) => void; onBusy: (busy: boolean) => void; disabled: boolean; }) { const [attachments, setAttachments] = useState([]); const [files, setFiles] = useState([]); const [path, setPath] = useState('/'); const [upload, setUpload] = useState(null); const [parseMethod, setParseMethod] = useState('disable'); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [refresh, setRefresh] = useState(0); usePendingCloudInput(busy || Boolean(upload)); useEffect(() => { if (!threadId) return; let live = true; Promise.all([cloudAgentsApi.call('attachments', { thread_id: threadId }), cloudAgentsApi.call('files', { thread_id: threadId, path })]) .then(([a, f]) => { if (live) { setAttachments(a.attachments); setFiles(f.files); } }) .catch(e => { if (live) setError(e instanceof Error ? e.message : '读取文件失败'); }); return () => { live = false; }; }, [threadId, path, refresh]); const act = async (task: () => Promise) => { setBusy(true); onBusy(true); setError(''); try { await task(); setRefresh(v => v + 1); } catch(e) { setError(e instanceof Error ? e.message : '文件操作失败'); } finally { setBusy(false); onBusy(false); } }; return
附件与产物 {selected.length ? '· 本条消息附带 ' + selected.length + ' 个文件' : ''}
{upload &&

{upload.file_name}

{upload.parse_supported && }
} {attachments.map(file => )} {threadId &&

会话文件 · {path}

{path !== '/' && }
{files.map(file =>
{file.is_dir ? : <>{file.name}}
)}
} {error &&

{error}。可刷新文件列表核对已上传的附件。

}
; }