u
This commit is contained in:
@@ -994,17 +994,23 @@ const actions = {
|
||||
}
|
||||
|
||||
const tempId = `temp-${Date.now()}`;
|
||||
const payloadMessage = fileAttachments.length > 0
|
||||
? JSON.stringify({ content: trimmed, attachments: fileAttachments })
|
||||
: trimmed;
|
||||
let finalContent = trimmed;
|
||||
if (fileAttachments.length > 0) {
|
||||
const formatAttr = (val) => String(val).includes(' ') ? `"${val}"` : String(val);
|
||||
const tags = fileAttachments.map((f) => {
|
||||
const vfsRelPath = f.path || `attachments/${f.name}`;
|
||||
const mime = f.mimeType || f.type || 'application/octet-stream';
|
||||
return `[ATTACHMENT name=${formatAttr(f.name)} path=${formatAttr(vfsRelPath)} type=${formatAttr(mime)}]`;
|
||||
});
|
||||
const prefix = tags.join(' ');
|
||||
finalContent = trimmed ? `${prefix}\n\n${trimmed}` : prefix;
|
||||
}
|
||||
|
||||
const optimisticMsg = {
|
||||
id: tempId,
|
||||
conversation_id: selectedConversationId,
|
||||
role: 'user',
|
||||
message: payloadMessage,
|
||||
content: trimmed,
|
||||
attachments: fileAttachments,
|
||||
message: JSON.stringify({ content: finalContent }),
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
@@ -1032,13 +1038,10 @@ const actions = {
|
||||
|
||||
try {
|
||||
const res = await modelconversationApi.addMessage(selectedConversationId, {
|
||||
message: payloadMessage,
|
||||
message: trimmed,
|
||||
attachments: fileAttachments.length > 0 ? fileAttachments : undefined,
|
||||
});
|
||||
const createdMsg = res?.message || optimisticMsg;
|
||||
if (!createdMsg.attachments && fileAttachments.length > 0) {
|
||||
createdMsg.attachments = fileAttachments;
|
||||
}
|
||||
chatAutomat.setState((prev) => {
|
||||
const alreadyHasRealId = prev.messages.some((m) => m.id === createdMsg.id && m.id !== tempId);
|
||||
if (alreadyHasRealId) {
|
||||
|
||||
Reference in New Issue
Block a user