|
|
|
@ -28,7 +28,7 @@ import { |
|
|
|
import { |
|
|
|
completeAttachmentUpload, |
|
|
|
createAttachmentUploadIntent, |
|
|
|
listAttachments, |
|
|
|
listAllAttachments, |
|
|
|
} from "../actions/agentResources"; |
|
|
|
import useSuperAgentSidebar from "./useSuperAgentSidebar"; |
|
|
|
import { |
|
|
|
@ -89,6 +89,9 @@ const toReadyUploadedFile = (attachment) => ({ |
|
|
|
attachmentId: String(attachment.id || attachment.attachment_id || attachment.attachmentId), |
|
|
|
name: attachment.file_name || attachment.filename || "未命名文件", |
|
|
|
status: attachment.status, |
|
|
|
messageId: attachment.message_id || attachment.messageId || "", |
|
|
|
mimeType: attachment.mime_type || attachment.mimeType || "", |
|
|
|
size: attachment.file_size || attachment.fileSize || 0, |
|
|
|
}); |
|
|
|
|
|
|
|
const buildSessionParams = (sessionId) => ({ |
|
|
|
@ -135,6 +138,7 @@ const useSuperAgentChat = ({ |
|
|
|
const [isCreatingChat, setIsCreatingChat] = useState(false); |
|
|
|
const [isCreatingTask, setIsCreatingTask] = useState(false); |
|
|
|
const [uploadedFileList, setUploadedFileList] = useState([]); |
|
|
|
const [conversationAttachments, setConversationAttachments] = useState([]); |
|
|
|
const [agentCategory, setAgentCategory] = useState("全部应用"); |
|
|
|
const [agentKeyword, setAgentKeyword] = useState(""); |
|
|
|
/** 任务大厅已选类型:null 表示尚未选择;tender 表示已进入标书引导 */ |
|
|
|
@ -160,17 +164,18 @@ const useSuperAgentChat = ({ |
|
|
|
const conversationId = String(activeConversationId || ""); |
|
|
|
if (!conversationId) { |
|
|
|
setUploadedFileList([]); |
|
|
|
setConversationAttachments([]); |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
let active = true; |
|
|
|
listAttachments(conversationId) |
|
|
|
.then((page) => { |
|
|
|
if (!active) return; |
|
|
|
setUploadedFileList( |
|
|
|
page.items |
|
|
|
.filter((attachment) => attachment.status === "ready" && !attachment.message_id) |
|
|
|
.map(toReadyUploadedFile) |
|
|
|
); |
|
|
|
listAllAttachments(conversationId) |
|
|
|
.then((attachments) => { |
|
|
|
if (!active) return; |
|
|
|
const readyFiles = attachments |
|
|
|
.filter((attachment) => attachment.status === "ready") |
|
|
|
.map(toReadyUploadedFile); |
|
|
|
setConversationAttachments(readyFiles); |
|
|
|
setUploadedFileList(readyFiles.filter((attachment) => !attachment.messageId)); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
superAgentWarn("chat.upload", "attachment_list_failed", { |
|
|
|
@ -1642,8 +1647,8 @@ const useSuperAgentChat = ({ |
|
|
|
status: "processing", |
|
|
|
})); |
|
|
|
const uploadData = await completeAttachmentUpload(uploadIntent.attachmentId); |
|
|
|
const attachmentPage = await listAttachments(conversationId); |
|
|
|
const readyAttachment = attachmentPage.items.find((attachment) => |
|
|
|
const attachmentList = await listAllAttachments(conversationId); |
|
|
|
const readyAttachment = attachmentList.find((attachment) => |
|
|
|
String(attachment.id || attachment.attachment_id || attachment.attachmentId) === uploadIntent.attachmentId |
|
|
|
) || uploadData?.data || uploadData || {}; |
|
|
|
if (readyAttachment.status !== "ready") { |
|
|
|
@ -1674,6 +1679,10 @@ const useSuperAgentChat = ({ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
setConversationAttachments((prev) => [ |
|
|
|
...prev.filter((item) => item.id !== uploadedFile.id), |
|
|
|
uploadedFile, |
|
|
|
]); |
|
|
|
setUploadedFileList((prev) => [...prev, uploadedFile]); |
|
|
|
message.success("文件上传成功,请输入指令后发送"); |
|
|
|
} catch (error) { |
|
|
|
@ -1864,6 +1873,8 @@ const useSuperAgentChat = ({ |
|
|
|
setTaskStage, |
|
|
|
conversationMessages, |
|
|
|
uploadedFileList, |
|
|
|
setUploadedFileList, |
|
|
|
conversationAttachments, |
|
|
|
uploadProgress, |
|
|
|
ordinaryChatList, |
|
|
|
sidebarError, |
|
|
|
|