fix(chat): preserve user image message order

This commit is contained in:
Xin Wang
2026-08-06 13:59:59 +08:00
parent 4a07abd7fc
commit 4d00e719c4
3 changed files with 45 additions and 19 deletions
@@ -49,6 +49,7 @@ import { WaveformTimelinePanel } from "@/components/ui/waveform-timeline";
import { useCameraPreview, type CameraPreview } from "@/hooks/use-camera-preview";
import { usePhotoCaptureTool } from "@/hooks/use-photo-capture-tool";
import {
createUserInputId,
useVoicePreview,
type ChatMessage,
type ClientToolDefinition,
@@ -799,6 +800,7 @@ function DebugVoicePanel({
sendText,
sendUserInput,
appendUserImage,
removeUserImage,
connect,
disconnect,
audioRef,
@@ -866,6 +868,7 @@ function DebugVoicePanel({
setSendingInput(true);
setInputError("");
let assetToken = "";
let inputId = "";
try {
const imageUrl = await fileToDataUrl(pendingImage.file);
const asset = await inputAssetsApi.uploadImage(pendingImage.file);
@@ -878,11 +881,13 @@ function DebugVoicePanel({
});
const timestamp = new Date().toISOString();
const result = await sendUserInput(parts);
appendUserImage(result.inputId, imageUrl, timestamp, text);
inputId = createUserInputId();
appendUserImage(inputId, imageUrl, timestamp, text);
await sendUserInput(parts, { inputId });
setTextDraft("");
setPendingImage(null);
} catch (sendError) {
if (inputId) removeUserImage(inputId);
if (assetToken) {
void inputAssetsApi.remove(assetToken).catch(() => {});
}